.NET framework include a Ping class that allows an application to determine whether a remote computer is accessible over the network.
Here is the complete source code of my Ping module written in C#:
First include the following namespaces on the Using directives.
Now insert this code for the Ping method.
static void Main(string args)
Console.Write("Enter the IP or Hostname to Ping: ");
string strhost = Console.ReadLine();
if (strhost.Length > 0)
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(strhost, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
Console.WriteLine("Ping was successful.");
For more C# coding tips & tricks, subscribe now.