C#获取本机所有IP(包括LAN 和外网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;
        }
    }
}

  

posted @ 2012-09-29 13:28  J_une  阅读(269)  评论(0编辑  收藏  举报