C# ping网络IP 实现网络状态检测

  1.  public string GetHostNameByIp(string ip)  
  2.         {  
  3.             ip = ip.Trim();  
  4.             if (ip == string.Empty)  
  5.                 return string.Empty;  
  6.             try  
  7.             {  
  8.                 // 是否 Ping 的通  
  9.                 if (this.Ping(ip))  
  10.                 {  
  11.                     System.Net.IPHostEntry host = System.Net.Dns.GetHostEntry(ip);  
  12.                     return host.HostName;  
  13.                 }  
  14.                 else  
  15.                     return string.Empty;  
  16.             }  
  17.             catch (Exception)  
  18.             {  
  19.                 return string.Empty;  
  20.             }  
  21.         }  

你可能感兴趣的:(C#)