C# 获取本机ip地址

代码
   private string GetLocalIp()
        {
            
string localIp;
            IPHostEntry host;
            host 
= Dns.GetHostEntry(Dns.GetHostName());         
            
if (host.AddressList.Count() > 1)
            {
                
//win7 ip
                 localIp = host.AddressList[1].ToString();
            }
            
else
            {
                 
//xp
                 localIp = host.AddressList[0].ToString();
            }
          
            
return localIp;
            
        }

 

posted @ 2010-11-09 15:44  ike_li  阅读(642)  评论(2编辑  收藏  举报