c# Ping with Simple Pinger Example
28/01/2010 Leave a comment
using System;
using System.Threading;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace ContextHelper
{
static class Pinger
{
public static void Ping(string url_or_IP)
{
using (Ping ping = new Ping())
{
try
{
Console.Write(" {0}...", url_or_IP);
PingReply reply = ping.Send(url_or_IP, 100);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Success - IP Address:{0}", reply.Address, reply.RoundtripTime);
}
else
{
Console.WriteLine(reply.Status);
}
}
catch (Exception ex)
{
Console.WriteLine("Error ({0})",
ex.InnerException.Message);
}
}
}
}
}