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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With