日期:2014-05-18 浏览次数:20883 次
NetworkInterface.GetIsNetworkAvailable()
------解决方案--------------------
ping一下不就好了
------解决方案--------------------
private static ManagementClass mc; private static ManagementObjectCollection moc; mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); moc = mc.GetInstances(); foreach (ManagementObject mo in moc) //查找网卡配置 { string s = ((string)mo["Caption"]); if (s == NIC) { if ((bool)mo["DHCPEnabled"]) //此网卡未配置过IP { string[] ips = new string[1] { LocalIP }; string[] masks = new string[1] { StationIPmask }; Object[] objs = new object[2] { ips, masks }; mo.InvokeMethod("EnableStatic", objs); NICValid = false; return; } string[] str = (string[])mo["IPAddress"]; //多个ip地址 if (str.Length >= 3) { InfoString = "不能有多个IP地址绑定在此网卡上!"; NICValid = false; return; } if (str.Length < 0) { InfoString = "请检查网卡设备!"; NICValid = false; return; } if (str[0] == "0.0.0.0") { InfoString = "请检查网卡与交换机正确连接!"; NICValid = false; return; } }