Sunday 15 January 2012

java - How to scan remote host port that in used? -


This is the code that I still get ...

  import Java.net *; Public class portscanner {public static zero main (string agre []) {int startPortRange = 0; Int stopPortRange = 0; StartPortRange = integer Paracet (Argos [0]); StopPortRange = integer Paracet (Argos [1]); (Inti = StartPortronage; i & lt; = stopPortRange; i ++) {Try {Socket ServerOS = New Socket ("127.0.0.1", i); System.out.println ("Port in use:" + i); ServerSok.close (); } Hold (exception e) {System.out.println ("Port is not in use:" + i); }}  

} For example, on the SMTP server, the system uses port 25, and I need to scan the port on the remote client which is connected to the SMTP server.

Your code should look like this:

 for  (int I = startPortRange; i & lt; = stopPortRange; i ++) {try {socket server Sok = new socket ("127.0.0.1", i); System.out.println ("Port in use:" + i); ServerSok.close (); } Hold (exception e) {System.out.println ("Port is not in use:" + i); }}  

No comments:

Post a Comment