I want to get the ping execution time and result in string after ping host. How can I do it?
This is how I used it -
private static void checkPing(String hostName) {
String[] command = { "cmd.exe", "/C", "ping " + hostName };
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReader buff = new BufferedReader(new InputStreamReader(p.getInputStream()));
String readline;
while ((readline = buff.readLine()) != null) {
if (readline.contains("Reply")) {
System.out.println("Pinged " + hostName + " in : "
+ readline.substring(readline.indexOf("time=") + 5, readline.indexOf("ms")) + " ms");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
Gives you the exact (reliable) ping latency in milliseconds for each ping request. You can then add the four of them, if required