How can i check if an ip has some ports opened? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can i check if an ip has some ports opened?

i'd like to do it in python

30th Apr 2018, 2:02 PM
Etabeta1🇮🇹
Etabeta1🇮🇹 - avatar
2 Answers
+ 1
In Java you can do it the following way: [Pseudo Code] /**Checks an IP for open ports between 0 and 3000**/ for (int port=0; port <= 3000; port++) try { Socket(ip,port); printf("Socket on port" + port + " is open"); } //if Socket() failed catch (Exception) { printf("Socket on port " + port + "is closed"); } I've actually never done it in python but I hope you got the idea. GL! :)
30th Apr 2018, 2:59 PM
Manuel Probst
0
thanks
30th Apr 2018, 3:55 PM
Etabeta1🇮🇹
Etabeta1🇮🇹 - avatar