简体   繁体   English

为什么Java InetAddress.isReachable()不能像JRE 1.7.x那样在JRE 1.8.x上运行

[英]Why does Java InetAddress.isReachable() not work on JRE 1.8.x like on JRE 1.7.x

I've written a programm a year ago and today I saw that this programm give me some curious output. 我一年前写了一个程序,今天我看到这个程序给了我一些好奇的输出。 One kind to detect PC's or notebooks in our network I'm using the InetAddress class. 一种检测我们网络中的PC或笔记本电脑我正在使用InetAddress类。 My programm works how it should, until Java 1.8.x runs on the executing machine, than the InetAddress.isReachable() gives me a "TRUE" also if there is no machine on that IP address. 我的程序工作原理应该如何,直到Java 1.8.x在执行机器上运行,而InetAddress.isReachable()在我的IP地址上没有机器的情况下给我一个“TRUE”。

private String ipAddress = "192.168.1.200";
inetAddr = InetAddress.getByName(ipAddress);
inetIsReachable = inetAddr.isReachable(8000);
debug += "   INET is reachable: " + inetIsReachable;
System.out.println(debug);

That is really strange, and I don't know how to detect this error. 这真的很奇怪,我不知道如何检测这个错误。

Kind regards proto 亲切的问候原型

°°°°°EDIT °°°°°编辑

I tried this code... running on Java 1.7 我试过这个代码...在Java 1.7上运行

  inetAddr = InetAddress.getByName(ipAddress);
  inetIsReachable = inetAddr.isReachable(8000);
// FALSE
  byte[] a = new byte[]{(byte) 192,(byte) 168,1,(byte) 200};
  inetAddr = InetAddress.getByAddress("192.168.1.200", a);
  inetIsReachable = inetAddr.isReachable(8000);
// also FALSE

But a ping on commandline reaches the machine! 但命令行ping命令到达机器!

°°°°°EDIT-2 °°°°°EDIT -2-

Java 1.8 Java 1.8

192.168.1.200 - InetAddress true - cmd ping true - there is a machine 192.168.1.200 - InetAddress true - cmd ping true - 有一台机器

192.168.1.202 - InetAddress true - cmd ping false - there is no machine 192.168.1.202 - InetAddress true - cmd ping false - 没有机器

Java 1.7 Java 1.7

192.168.1.200 - InetAddress false - cmd ping true - there is a machine 192.168.1.200 - InetAddress false - cmd ping true - 有一台机器

192.168.1.202 - InetAddress false - cmd ping false- there is no machine 192.168.1.202 - InetAddress false - cmd ping false-没有机器

这看起来像bug#JDK-8159410 ,显然是在8u73之后推出的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM