Geeks With Blogs

WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Inside and Out... An attempt to understand technology better...

.NET Framework 2.0 carries a lot of good for developers. And as part of my exploration, I came across the neat Ping class - your managed implementation for the ICMP call to check the availability of a server on TCP/IP network. Implemented in the System.Net.NetworkInformation namespace, all it takes is just two lines of code to get the work done.

Below is the source to a quick .NET ping utility I wrote in the past 7 minutes:

using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

using System.Net.NetworkInformation;


namespace PingDotNET


class Program


static void Main(string[] args)


// display the details

Console.WriteLine("Ping .NET - by Gaurav Khanna []");

Console.WriteLine("Written using .NET FX 2.0\n");

// Did we get the address/domain name to ping?

if (args.Length == 0)


Console.WriteLine("Usage: PingDotNET ");



// instantiate the Ping class

Ping refPing = new Ping();

PingReply refPingResult = null;

// Invoke the "correct" Ping.Send overload [and we do blocking call]...

Console.WriteLine("Pinging {0}...\n",args[0]);

refPingResult = refPing.Send(args[0]);

Console.WriteLine("Ping Status: {0}",refPingResult.Status.ToString());

Console.WriteLine("RoundTrip Time [millisec]: {0}",refPingResult.RoundTripTime);

if (refPingResult.Options != null)

Console.WriteLine("TTL: {0}",refPingResult.Options.Ttl.ToString());



Posted on Monday, July 12, 2004 7:22 PM .NET Framework | Back to top

Comments on this post: Managed Pinging...

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Gaurav Khanna | Powered by: