The following code shows you how to simulate the "ping" command with the J2SE Tiger
InetAddress.isReachable method.
import java.io.*;
import java.net.*;
public class reachable{
public static void main(String args[]) {
String[] addrs=
{"www.java.sun.com","www.yahoo.com","www.google.com"};
try{
for(int i=0;i<addrs.length;i++)
{
InetAddress addr=InetAddress.getByName(addrs[i]);
System.out.println("Name:"+addr.getHostName());
System.out.println("Addr:"+addr.getHostAddress());
//the address will be checked for 5005 miliseconds
System.out.println("Reach:"+addr.isReachable(5005));
}
}catch(UnknownHostException e){
System.out.println(e.getMessage());
}catch(IOException e){
System.err.println(e.getMessage());
}
}
}