当前位置:主页 > 软件编程 > .NET代码 >

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

时间:2021-06-12 08:20:01 | 栏目:.NET代码 | 点击:

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

public string GetHostNameByIp(string ip) 

{ 

ip = ip.Trim(); 

if (ip == string.Empty) 

return string.Empty; 

try 

{ 

// 是否 Ping 的通 

if (this.Ping(ip)) 

{ 

System.Net.IPHostEntry host = System.Net.Dns.GetHostEntry(ip); 

return host.HostName; 

} 

else 

return string.Empty; 

} 

catch (Exception) 

{ 

return string.Empty; 

} 

} 

您可能感兴趣的文章:

相关文章