开发者

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

freshman, both here and in Java i 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 be used to test whether certain port is 开发者_如何学Copen(here is port 1111 on 192.168.2.3), just wandering is there any other way?? not using socket() maybe??


To simplyfy things a bit: yes, establishing a connection is correct way to probe for open port, and if you even find other method, it will be using socket() under the hood.

Complexity of the whole problem comes from the fact that "open port" is a number one suspect in every security book out there. System administrators use a bunch of tricks to fight so called "port scanning". This includes reporting a "false positive" (claiming that port is open while it is not) to any software that behaves like a port scanner (that is: makes a connection and disconnects without sending any data).

So in reality the best way is to establish connection, send request and process response. Every other approach can fail under certain network/host/security configurations, leaving your user puzzled as to why his application doesn't work when it claims there is no problem with connection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜