How To

How To: Use the Ping class

Networking In The Hand includes the Ping class (In the InTheHand.Net.NetworkInformation namespace). The component allows you to determine if a network path to a particular host is available and whether the host is responding. It doesn’t guarantee that a particular service is running on the server (HTTP, FTP etc). You can perform a Ping in a couple of lines of code, the class has been designed to be an exact subset of the equivalent class in the full .NET framework. The following is an example of the simplest ping request using a default payload and timeout settings.

InTheHand.Net.NetworkInformation.Ping p = new InTheHand.Net.NetworkInformation.Ping();
InTheHand.Net.NetworkInformation.PingReply reply = p.Send(“”);

if (reply.Status == IPStatus.Success)
   string message = string.Format(“Address: {0}rnRoundTrip time: {1}rnTime to live: {2}rnDon’t fragment: {3}rnBuffer size: {0}”,

   MessageBox.Show(message, “Ping”);
   MessageBox.Show(reply.Status.ToString(), “Ping”);

The class allows you to further customise the request. You can specify your own data payload for example, or set a different timeout value (the default is 5 seconds).

By Peter Foot

Microsoft Windows Development MVP