2012年3月23日 星期五

C# 利用IP查詢Hostname問題



Dns.Resolve 與 GetHostByAddress(String)
在.net 2.0後版本都會顯示已過時

但M$DN 所建議的替代方案Dns.GetHostEntry
輸入IP並不能有效取得Hostname ,我遇到和下面一模一樣問題
http://bytes.com/topic/net/answers/453896-dns-gethostentry


外國人討論此問題也有不少討論串
(1).
http://bytes.com/topic/net/answers/829960-dns-gethostentry-not-working-same-dns-resolve-dns-gethos

(2).
這個討論串值得一看,有說明了出問題原因,雖然無法解決,但大家爭相表達不滿XDDD?
http://social.msdn.microsoft.com/Forums/da-DK/netfxnetcom/thread/e2059b78-3493-457b-b632-0500be197478

The issue is the reverse lookup. Traditionally DNS Servers are supposed to resolve the names to addresses. The reverse of that - looking up a host name based on IPAddress is not reliable and in Ipv6 it is not supported. So my recommendation is to not to write apps that rely on reverse lookup.

(3).
最慘的是,M$ connect上有人發文指出這個問題,MS的回覆ˊˋ
System.Net.DNS.GetHostByAddress(<IP>) doesn't resolve host names on remote nodes

Microsoft 在 2006/2/23 於 下午 01:50 所公佈
The issue here lies in the OS implementation of DNS which System.Net utilizes. A bug has been filed against the OS. This issue is fixed in Windows Vista.

https://connect.microsoft.com/VisualStudio/feedback/details/97815/system-net-dns-gethostbyaddress-ip-doesnt-resolve-host-names-on-remote-nodes


爬了一小時文,沒什麼結論
GetHostEntry能支援IPv6
IP反查HostName要不就靠DNS Server幫忙(若GetHostEntry必須重設DNS 反向查詢功能)

不然舊版Resolve也不保證一定查得到??ˊ3ˋ


所以Dns.Resolve與Dns.GetHostEntry究竟用哪個好(汗)

0 意見:

張貼留言