Inside and Out...

An attempt to understand technology better...

  Home  |   Contact  |   Syndication    |   Login
  160 Posts | 0 Stories | 12 Comments | 181 Trackbacks

News


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.
Disclaimer

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.

Twitter





Tag Cloud


Archives

Post Categories

Image Galleries

Links

Monday, July 12, 2004 #

.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;

#endregion

namespace PingDotNET

{

class Program

{

static void Main(string[] args)

{

// display the details

Console.WriteLine("Ping .NET - by Gaurav Khanna [gkhanna@gmail.com]");

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 ");

return;

}

// 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());

}

}