Ping a host in Java

Description

The following code shows how to ping a host.

Example


import java.net.InetAddress;
/*from   w w  w. ja v  a  2 s .co m*/
public class Main {
  public static void main(String[] args) throws Exception {
    InetAddress address = InetAddress.getByName("17.16.15.14");

    boolean reachable = address.isReachable(10000);

    System.out.println("Is host reachable? " + reachable);
  }
}




















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode