I want to get the ping execution time and result in string after ping host. How can I do it?
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.");
}
But this will use ICMP ping only in windows system.