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;
}