import java.net.*; import java.io.*; public class Ping { public static void main(String[] args) throws Exception { while(true) { InetAddress address = InetAddress.getByName(args[0]); long nanos = System.nanoTime(); if(address.isReachable(50000)) { nanos = System.nanoTime() - nanos; long millis = Math.max(0, Math.round(nanos / Math.pow(10, 6)) - 1000); System.out.println("Reply from " + address.getHostAddress() + ": time=" + millis + "ms"); Thread.sleep(Math.max(0, 1000 - millis)); } else { System.out.println("Is not reachable"); break; } } } }