/// <summary> /// 获取本机的IP地址 /// </summary> /// <returns></returns> /// public static string GetLocal1IP() { String[] addresses = GetLocalIP(); if (addresses != null && addresses.Length > 0) { return addresses[0]; } return null; } /// <summary> /// 获取本机的IP地址 /// </summary> /// <returns></returns> public static string[] GetLocalIP() { ManagementClass mAdapter = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection mo = mAdapter.GetInstances(); foreach (ManagementBaseObject m in mo) { if ((bool)m["IpEnabled"] == true) { return (string[])m["IPAddress"]; } } mo.Dispose(); return null; }
时间: 2024-10-10 13:06:48