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