public static bool PingServer(string ipOrHostName)
{
try
{
Ping ping = new Ping();
PingOptions pingOptions = new PingOptions();
pingOptions.DontFragment = true;
string data = "";
byte[] buffer = Encoding.UTF8.GetBytes(data);
int timeout = 120;
PingReply reply = ping.Send(ipOrHostName, timeout, buffer, pingOptions);
string result = reply.Status.ToString();
if (result == "Success")
{
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}