Which DNS Server

The domain name system works my moving up a chain of DNS servers one-by-one, until the domain-to-IP mapping entry being looked for is found. Usually this process starts off at your ISP, and works it way towards the 13 (don't quote me on that exact number) root DNS servers run by UUNET and other large providers.

You can determine the DNS servers that your computer primarily uses by typing the following at a command prompt:

Code:
ipconfig /all

Getting this information in .NET is a different story though. Other than an unmanaged solution I believe you're out of luck.
 
Thanks, are the root server IP at UUNET static? I would like to hard-code them into my component as the default DSN servers.
 
This sounds like a bad idea to me - why would you hardcode those? The whole point of DNS is that it should be automatic, traversing a tree to get the desired result, as Derek said.
 
I dont want to hard code these, but I do need to solve the problem (ie. I need to have a DNS ip at runtime).

If I can get the machine's Primary DNS IP that would be ideal, but failing that I will use these. I plan to allow the user to override these.

Any further help would be much appreciated
 
Sure, I am writing a email validation component which validates the addresses by chatting with the mail server.

I need a DNS IP so that I can get the email server's mx record.
 
I'm positive there's a way to do this using WSALookupServiceBegin/Next however my mind is drawing a blank. Have a look into those two functions and let me know if you find anything, as I just don't have the time.

Also, while I don't consider this a perfect solution, you can locate the DNS server IPs under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{guid}\

You'd be looking for values named "NameServer", however that value is not present under all of the contained keys.
 
Back
Top