networking - in Java, how do I know if certain port on a host is open??(besides using socket if possible) -


freshman, both here , in java know codes like:

socket clientsocket=null;  try    {      clientsocket=new socket(192.168.2.3,1111);   system.out.println("port open");      clientsocket.close();    }    catch(exception   e)    {      system.out.println("port closed"); } 

can used test whether port open(here port 1111 on 192.168.2.3), wandering there other way?? not using socket() maybe??

to simplyfy things bit: yes, establishing connection correct way probe open port, , if find other method, using socket() under hood.

complexity of whole problem comes fact "open port" number 1 suspect in every security book out there. system administrators use bunch of tricks fight called "port scanning". includes reporting "false positive" (claiming port open while not) software behaves port scanner (that is: makes connection , disconnects without sending data).

so in reality best way establish connection, send request , process response. every other approach can fail under network/host/security configurations, leaving user puzzled why application doesn't work when claims there no problem connection.


Comments