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

后端 未结 10 1626
陌清茗
陌清茗 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 12:38

    I am not sure what was the state when the original question was asked back in 2012.

    As it stands now, ping will be executed as a root. Through the ping executable's authorization you will see the +s flag, and the process belonging to root, meaning it will run as root. run ls -liat on where the ping is located and you should see it.

    So, if you run InetAddress.getByName("www.google.com").isReacheable(5000) as root, it should return true.

    you need proper authorizations for the raw socket, which is used by ICMP (the protocol used by ping)

    InetAddress.getByName is as reliable as ping, but you need proper permissions on the process to have it running properly.

提交回复
热议问题