易丰科技
标题:
c# code snippet 判断是否在线
[打印本页]
作者:
Calvin
时间:
2011-10-3 19:54
标题:
c# code snippet 判断是否在线
//判断是否在线
public static bool IsOnline()
{
if (!NetworkInterface.GetIsNetworkAvailable())
return false;
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterface in networkInterfaces)
{
if (networkInterface.OperationalStatus != OperationalStatus.Up)
continue;
IPInterfaceProperties properties = networkInterface.GetIPProperties();
UnicastIPAddressInformationCollection infos = properties.UnicastAddresses;
foreach (UnicastIPAddressInformation info in infos)
{
if (System.Net.IPAddress.IsLoopback(info.Address))
continue;
string sInfo = info.Address.ToString();
if (sInfo == System.Net.IPAddress.IPv6None.ToString())
continue;
if (sInfo == System.Net.IPAddress.None.ToString())
continue;
return true;
}
}
return false;
}
复制代码
欢迎光临 易丰科技 (http://forum.yftek.com/)
Powered by Discuz! X3