Few days ago I needed to check whether certain server was dead or alive. Any network guy will tell you that ping is your mate. While he also might tell you that ping might not work at all times (damn you firewall) I will ignore this unfortunate part for a moment. Suffice to say that ping works for my scenario.

While I used to solve this issues with good old P/Interop, I decided to check whether .NET Framework 3.5 (one that I used) is smarter that old grandpa 2.0. And what do you know, there is Ping class available inside System.Net.NetworkInformation namespace.

Class was made by someone who clearly hadn't read Framework Design Guidelines but it does provide complete solution. At least code is easy enough:

var ping = new Ping();
var reply = ping.Send("");
if (reply.Status == IPStatus.Success) {
Debug.WriteLine(reply.RoundtripTime + " ms.");

Leave a Reply

Your email address will not be published. Required fields are marked *