IPAdreess 以及Dns.GetHostByName(string)”已过时

“System.Net.Dns.GetHostByName(string)”已过时之类问题解决总结
程序出现: 警告 1 “System.Net.Dns.GetHostByName(string)”已过时:“GetHostByName is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202”
当从VS2003升级到vs2005,或者vs2005到vs2008,vs2010,经常遇到一些警告过时,此类问题解决主要看提示:GetHostByName is obsoleted for this type, please use GetHostEntry instead. GetHostByName类型已经过时,请用GetHostEntry代替,其它类似问题都可以这样解决。只需要将GetHostByName换成GetHostEntry即可。



IPHostEntry here = Dns.GetHostEntry(Dns.GetHostName());
IPAddress localaddress=null;
foreach (IPAddress _ip in here.AddressList)
{
if ( _ip.AddressFamily.ToString().ToUpper() == "INTERNETWORK")
{
localaddress = _ip;
}
}

由于有ipv6协议,这里判断ip地址族,
【IPAdreess 以及Dns.GetHostByName(string)”已过时】

    推荐阅读