Java tutorial
import java.io.IOException; import java.net.InetAddress; public class MainClass { public static void main(String[] args) throws IOException { try { int timeout = 2000; InetAddress[] addresses = InetAddress.getAllByName("www.java2s.com"); for (InetAddress address : addresses) { if (address.isReachable(timeout)) System.out.printf("%s is reachable%n", address); else System.out.printf("%s could not be contacted%n", address); } } catch (Exception e) { System.out.printf("Unknown host: %s%n", "www.java2s.com"); } } }