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;
}
{
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;
}