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

最近项目中须要实现 类 cmd 命令ping 的操做。查看当前Ip是否畅通。代码以下:orm

第一步 引用:System.Netip

代码以下:cmd

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;  
     }
相关文章
相关标签/搜索