日期:2014-05-18 浏览次数:21115 次
本地IP地址 using System.Net; IPHostEntry ipHost = Dns.Resolve(Dns.GetHostName()); ; IPAddress ipaddress = ipHost.AddressList[0]; string ips = ipaddress.ToString(); MAC地址 string strMac = ""; NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in interfaces) { if (ni.OperationalStatus == OperationalStatus.Up) { strMac += ni.GetPhysicalAddress().ToString() + "|";//MAC地址 } } ni.OperationalStatus.ToString();//网络连接状态
------解决方案--------------------
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled='True' and MACAddress = '" + MACAddress + "'"); ManagementObjectCollection queryCollection = query.Get(); foreach (ManagementObject mo in queryCollection) { if ((bool)mo["IPEnabled"] == true) { if (mo["IPAddress"] != null) strIP = ((string[])mo["IPAddress"])[0]; } else { strIP = "0.0.0.0"; } }