long currentTime = System.currentTimeMillis();
boolean isPinged = InetAddress.getByName(servername).isReachable(2000); // 2 seconds
currentTime = System.currentTimeMillis() - currentTime;
if(isPinged) {
System.out.println("pinged successfully in "+ currentTime+ "millisecond");
} else {
System.out.println("PIng failed.");
}
Но при этом пинг ICMP будет использоваться только в системе Windows.