I think you need to distinguish between the time spent by the server (machine) and the time for processing on the server side. For example, ping will simply measure ICMP response time, which is a return of the low-level network protocol. If you take into account the TCP stack, and then the subsequent processing by the server, this period of time will be longer.
From your question, it looks like ping (ICMP) is what you want. In JDK 5 and above, you can:
String host = "192.168.0.1" int timeOut = 5000; boolean status = InetAddress.getByName(host).isReachable(timeOut)
and you will need time using System.nano() or the like.
source share