IsReachable always returns true no matter what IP address

So, I use isReachable to "ping" the address in my java code. This block of code is used for everyone:

    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();
    }

My problem is that no matter what I use for my IP address, it always returns true. Even if I change it to an empty string. Any ideas why?

+3
source share
1 answer

A way to check if any address is available using java.net.InetAddress.isReachable () methods. The implementation of these methods is native and tries to do everything possible to "ping" the address provided by InetAddress.

, Windows Linux/Unix java.net.InetAddress.isReachable().

Windows, , ICMP "ping" . , Java SE 5 TCP 7 ( ) - .

Linux/Unix, , ICMP "ping" . , java.net.InetAddress.isReachable() "ping" ; , , TCP 7, Windows.

, Linux/Unix ping root, java.net.InetAddress.isReachable() , Java root.

- ICMP. , ping. .

FROM: Simone Bordet

+2

All Articles