[System.Net.Dns]::GetHostEntry method resolves IP to HOSTNAME without PTR record?

孤街浪徒 提交于 2019-12-12 10:19:47

问题


I am trying to use Dns.GetHostEntry method to get the HOSTNAME for a given IP from the DNS server.

According to the documentation, the method first tries to do a reverse lookup on the IP address. In my case this is always successful when I use Dns.GetHostEntry.

Now, the strange thing is that for the same IP nslookup doesn't give me anything. It either times out or gives me error: UnKnown can't find 10.4.202.16: Non-existent domain. When I look into the DNS server (2008 R2), I can not find any PTR records in de reverse lookup zone. So the fact that nslookup fails doesn't surprise me much.

But what is going on here? Is Dns.GetHostEntry using some undocumented ways to obtain the HOSTNAME?


回答1:


I just ran into this, though slightly different on my laptop. It is called "RedMonster". I'm at a facility where I've been given an IP address via DNS. And if I do reverse lookup on the ip address using nslookup I get an address something like "123.123.123.123-dns.organization.ch". However, if I use GetHostEntry to do a reverse lookup, I get "RedMonster.organization.ch". Which makes me think that GetHostEntry is doing something "clever" when run in the default way, and must be using a local cache to do the reverse lookup.

I don't know how to force the system to use DNS, however, which I would like.




回答2:


Those metods have bugs: http://blog.tyang.org/2011/04/15/problem-with-dns-name-resolution-when-using-system-net-dns-class/ I suggest to use Solution 5 from above post.



来源:https://stackoverflow.com/questions/16664989/system-net-dnsgethostentry-method-resolves-ip-to-hostname-without-ptr-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!