When your C# application is running on a customer’s system, you have no guarantee that there are any DNS servers configured. You can find out what (if any) DNS servers are configured by using the .NET Registry class methods to examine the DNS Registry values.
Fortunately, all Windows platforms store the DNS server information in the same place:
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
This key stores all the DNS parameters from the Internet Protocol Properties window as separate data values. Table describes some of the values that are stored under this key.
| Data Value | Description |
|---|---|
| DatabasePath | The location of the host’s file |
| Domain | The name of the system’s domain |
| Hostname | The name of the system’s DNS host |
| NameServer | The list of DNS servers |
| SearchList | A list of DNS domains to append to the end of hostnames in DNS name searches |
The value of most interest here is NameServer. This should contain a single string value representing all the configured DNS servers, separated by spaces. The primary DNS server will be listed first, followed by the alternate servers.
| Note | If the workstation uses DHCP to dynamically assign an IP address, it may also dynamically assign DNS server addresses. These values are stored with the DHCP information of the connection, in place of the normal IP parameters section shown for this discussion. |
You can create a C# program to query this Registry value using the .NET Registry class.

No comments:
Post a Comment