C#获取本机所有IP地址(包括局域网和本机外网IP)
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; } }}
TAG: