using System.Net.NetworkInformation;
using System.Text;
public static int PingHost(string ipStr)
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "a";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1000;
try
{
PingReply reply = pingSender.Send(ipStr, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
return 0;
}
}
catch { }
return 1;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/20959.html