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 on 2012-09-25 17:04  计划  阅读(2364)  评论(3编辑  收藏  举报