所以我一直在使用isReachable为“平”的地址在我的Java代码。这个代码块是每个人都似乎使用:isReachable总是返回true不管IP地址是什么
try
{
InetAddress address = InetAddress.getByName("172.16.2.0");
// Try to reach the specified address within the timeout
// periode. If during this periode the address cannot be
// reach then the method returns false.
boolean reachable = address.isReachable(10000);
System.out.println("Is host reachable? " + reachable);
} catch (Exception e)
{
e.printStackTrace();
}
我的问题是,不管我用我的IP地址,它总是返回true。即使我将其更改为空字符串。任何想法为什么?
你使用Java 1.5?一个错误报告已经打开:http://bugs.sun.com/view_bug.do?bug_id=5067312。现在已经解决了,所以如果您使用的是1.5版本,请尝试使用更新的Java版本。 – 2012-07-21 10:09:53