Here is the method implementation:
public bool PingNetwork(string hostNameOrAddress)
{
bool pingStatus = false;
using (Ping p = new Ping())
{
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
try
{
PingReply reply = p.Send(hostNameOrAddress, timeout, buffer);
pingStatus = (reply.Status == IPStatus.Success);
}
catch (Exception)
{
pingStatus = false;
}
}
return pingStatus;
}
Please Vote & "Mark As Answer" if this helps you. Let me know, if you have any issues.