所以我一直在使用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