您的位置:首页 > 编程语言 > C#

c#实现ping

2016-03-02 16:12 357 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: