Friday 9 October 2015

Java Reachability Of Nodes

InetAddress class provides two methods to check the reachability of any node in the network.

isReachable(int timeout)
isReachable(NetworkInterface netif, int ttl, int timeout)

The timeout value, in milliseconds, indicates the maximum amount of time the try should take.

The network interface and ttl parameters let the caller specify which network interface the test will go through and the maximum number of hops the packets should go through.


I will explain NetworkInterface later.

import java.io.IOException;
import java.net.InetAddress;

public class Main {
  public static void main(String args[]) throws IOException {
    InetAddress addr = InetAddress.getByName("www.google.com");
    System.out.println(addr.isReachable(1000));
  }
}


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment