标签:
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;
}
}
标签:
原文地址:http://www.cnblogs.com/zhaoCat/p/5818999.html