c# – GetHostEntry和GetHostByName之间的区别?
发布时间:2020-12-15 08:39:44 所属栏目:百科 来源:网络整理
导读:在 MSDN,它提到GetHostByName已过时.替换是GetHostEntry.它们有什么区别? 解决方法 看起来像GetHostEntry做了更多的错误检查,也支持 Network Tracing GetHostByName已解压缩: public static IPHostEntry GetHostByName(string hostName){ if (hostName ==
在
MSDN,它提到GetHostByName已过时.替换是GetHostEntry.它们有什么区别?
解决方法
看起来像GetHostEntry做了更多的错误检查,也支持
Network Tracing
GetHostByName已解压缩: public static IPHostEntry GetHostByName(string hostName) { if (hostName == null) throw new ArgumentNullException("hostName"); Dns.s_DnsPermission.Demand(); IPAddress address; if (IPAddress.TryParse(hostName,out address)) return Dns.GetUnresolveAnswer(address); else return Dns.InternalGetHostByName(hostName,false); } GetHostEntry已解压缩: public static IPHostEntry GetHostEntry(string hostNameOrAddress) { if (Logging.On) Logging.Enter(Logging.Sockets,"DNS","GetHostEntry",hostNameOrAddress); Dns.s_DnsPermission.Demand(); if (hostNameOrAddress == null) throw new ArgumentNullException("hostNameOrAddress"); IPAddress address; IPHostEntry ipHostEntry; if (IPAddress.TryParse(hostNameOrAddress,out address)) { if (((object) address).Equals((object) IPAddress.Any) || ((object) address).Equals((object) IPAddress.IPv6Any)) throw new ArgumentException(SR.GetString("net_invalid_ip_addr"),"hostNameOrAddress"); ipHostEntry = Dns.InternalGetHostByAddress(address,true); } else ipHostEntry = Dns.InternalGetHostByName(hostNameOrAddress,true); if (Logging.On) Logging.Exit(Logging.Sockets,(object) ipHostEntry); return ipHostEntry; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |