Tuesday, February 21, 2012

Send Ping Command in C#

I had a scenario which need to test  whether server available or not for my application.So i wrote following code to accomplish that.

.net framework has set of classes which support to Ping to the specified host.

public bool IsAvailableHost(string hostName)
{
var ping = new Ping();
try
{
PingReply reply = ping.Send(hostName);
return reply != null && reply.Status == IPStatus.Success;
}
catch (Exception ex)
{
throw ex;
}
}

No comments:

Post a Comment