Here is what I use to ping an IPv4-Address and to record the actual response time in ms. Unfortunately I never get a valid response.. The request always times out. 0 is always returned. Please help :)
private long pingHost(String host, int port) {
try {
Inet4Address inet4 = (Inet4Address)InetAddress.getByName(host);
long start = System.currentTimeMillis();
if(inet4.isReachable(5000)){
long end = System.currentTimeMillis();
long total = end-start;
System.out.println(total);
return total;
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}