using System.Net; namespace Jihua.Cnblogs.Com { class NetHelper { /// <summary> /// 获取所有本机IP地址,包括局域网IP和本机外网IP(如果有) /// </summary> /// <returns>192.168.1.10|220.181.112.143</returns> public static string GetAllIP() { IPAddress[] IP = Dns.GetHostAddresses(Dns.GetHostName()); int m_count = IP.Length; string m_AllIP = string.Empty; for (int i = 0; i < m_count; i++) { if (i > 0) m_AllIP= m_AllIP+"|"; m_AllIP += IP[i].ToString() ; } return m_AllIP; } } }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)