C# 得到本机局域网IP地址

 

C#获取本机IP搜集整理7种方法:http://blog.csdn.net/frombegintoend/article/details/7713097

使用IPHostEntry获取本机局域网地址
            string hostName = Dns.GetHostName();
            IPHostEntry localHost = Dns.GetHostEntry(hostName);
            for (int i=0; i < localHost.AddressList.Length ; ++i)
            {
                if (localHost.AddressList[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    Console.WriteLine(localHost.AddressList[i].ToString());
                }
            }

 

posted @ 2015-05-27 17:59  bovenson  阅读(381)  评论(0编辑  收藏  举报