Why does InetAddress.isReachable return false, when I can ping the IP address?

后端 未结 10 1485
陌清茗
陌清茗 2020-11-22 12:24
InetAddress byName = InetAddress.getByName("173.39.161.140");
System.out.println(byName);
System.out.println(byNam         


        
10条回答
  •  太阳男子
    2020-11-22 13:03

    Just mentioning it explicitly since the other answers don't. The ping part of isReachable() requires root access on Unix. And as pointed out by bestsss in 4779367:

    And if you ask why ping from bash doesn't, actually it does need as well. Do that ls -l /bin/ping.

    Since using root was not an option in my case the solution was to allow access to port 7 in the firewall to the specific server I was interested in.

提交回复
热议问题