日期:2014-05-17 浏览次数:21023 次
/// <summary> /// 获取当前网卡IP地址 /// </summary> /// <returns></returns> public static string GetNetCardIP() { try { string stringIP = ""; ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection MOC = MC.GetInstances(); foreach (ManagementObject MO in MOC) { if ((bool)MO["IPEnabled"] == true) { string[] IPAddresses = (string[])MO["IPAddress"]; if (IPAddresses.Length > 0) { stringIP = IPAddresses[0].ToString(); } } } return stringIP; } catch { return ""; } }