2

nslookup google.co.kr IP results change whenever I tried this command

But in C#, using method GetHostEntry() in library System.Net.Dns, I got always same results.

I wanna know why this phenomenon has been occured and whether I can get same reuslt as nslookup using GetHostEntry.

Shaharyar
  • 12,254
  • 4
  • 46
  • 66
Jehyun Shim
  • 91
  • 2
  • 11

2 Answers2

2

When you call GetHostEntry() you will get whatever data is in the local DNS cache. If the hostname has not been retrieved recently it will query the DNS servers to get the information. The NSLOOKUP command will query the DNS servers every time, ignoring whatever might be in the local cache. This might result in the same data coming back over and over, depending on the caching at your DNS server.

For most simple DNS results, you'll get the same data every time. For clustered services that are hosted on groups of servers - such as google - the results will be chosen by the google DNS servers based on loading and so on. In cases like that you can get different results from successive invocations of NSLOOKUP, but GetHostEntry() will return the same results until the entry expires from the local DNS cache.

DNS caching helps reduce loading on the DNS servers as well as reducing network traffic. Unless you need a different set of results each time, GetHostEntry() will be faster and more efficient.

Corey
  • 15,524
  • 2
  • 35
  • 68
  • Thank you very much. But I have to get IP information as many as possible. So I need to flush that cache and get another IP information for specific hostname. Is there any method to flush the chace in C# code(using library)? – Jehyun Shim Jul 15 '13 at 05:52
  • @JehyunShim The only way to guarantee getting different results each time is to directly query the DNS server responsible for those records. Use `nslookup -type=ns google.co.kr` to get a list of responsible nameservers, then use one (or more) of those to query against. `nslookup google.co.kr 216.239.34.10` for instance gives different results each time. – Corey Jul 15 '13 at 06:17
0

When you I used GetHostEntry() I noticed that this function does not support DNS records from type CNAME and throws an exception. nslookup supports DNS records from type CNAME.

  • This mostly seems like a critique of the previous answer. You hint at a solution regarding NSLookup. Can you expand on that, so that this provides a full answer to the original problem? – Jeremy Caney May 07 '22 at 02:12
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31706817) – Kuro Neko May 11 '22 at 06:22