您的位置:首页 > 理论基础 > 计算机网络

C# Ping Ip 网络是否畅通实现

2016-06-03 16:33 1051 查看
最近项目中需要实现 类 cmd 命令ping 的操作。查看当前Ip是否畅通。代码如下:

第一步 引用:System.Net

代码如下:

protected bool Ping(string ip)
{
Ping p = new System.Net.NetworkInformation.Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "Test Data!";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1000;
PingReply reply = p.Send(ip, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
return true;
else
return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: