Java Utililty Methods InetAddress Ping

List of utility methods to do InetAddress Ping

Description

The list of methods to do InetAddress Ping are organized into topic(s).

Method

booleanping(InetAddress addr, NetworkInterface ni)
ping
return ping(addr, ni, 255, 5000);
booleanping(InetAddress host)
Method taken from http://stackoverflow.com/questions/2448666/how-to-do-a-true-java-ping-from-windows
try {
    String cmd = "";
    if (System.getProperty(SYSTEM_PROPERTY_OS_NAME).toLowerCase().startsWith(OS_NAME_WINDOWS)) {
        cmd = WINDOWS_PING_CMD + host.getHostAddress();
    } else {
        cmd = UNIX_PING_CMD + host.getHostAddress();
    Process myProcess = Runtime.getRuntime().exec(cmd);
...
intping(InetAddress target)
Get the answer time of the host
return ping(target, 300);
booleanpingFromLocalAddress(InetAddress localAddr)
ping From Local Address
boolean connected = false;
Socket socket = null;
try {
    socket = new Socket(IPv6_ONLY_SERVER_IP, IPv6_ONLY_SERVER_PORT, localAddr, 0);
    out.println("Created!");
    connected = true;
} catch (IOException e) {
    out.println("Failed to connect");
...
booleanpingUsingInetAddress()
ping Using Inet Address
try {
    return InetAddress.getByName("4.2.2.2").isReachable((int) TimeUnit.SECONDS.toMillis(15));
} catch (Exception e) {
    return false;
longpingWindows(InetAddress address, long timeout)
ping Windows
boolean reached = false;
long start = System.currentTimeMillis();
long end = (start - 1);
try {
    String line;
    ProcessBuilder processBuilder = new ProcessBuilder(
            new String[] { "ping", address.getHostAddress(), "-w", String.valueOf(timeout), "-n", "1" });
    Process process = processBuilder.start();
...
intping(final InetAddress address)
ping
Long start = System.currentTimeMillis();
try {
    if (!address.isReachable(2000))
        return -1;
    return (int) (System.currentTimeMillis() - start);
} catch (IOException ex) {
    return -1;