none
Accessing Automatic DNS association via WMI RRS feed

  • Question

  • Hi folks,
    I'm writing cause I need to establish if a network card TCP/IP setting is set to acquire automatically a DNS server or not.

    I have found that when I set the values for DNS servers in Control Panel, the Win32_NetworkAdapterConfiguration.DNSServerSearchOrder is updated accordingly.

    The problem is that when DNS is set to auto, the search order is still populated with default values, and I can't understand if this are automatic values or manually set.

    Is there any other WIM_*/Win32_* class one can inspect to find out this setting?

    At the moment I have found as only option to write to the registry key:

    HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{<card ID>}\NameServer

    Thanks in advance
    Francesco

    • Edited by fditolla Tuesday, September 16, 2008 10:40 AM
    Tuesday, September 16, 2008 7:21 AM

Answers

  • More than likely the dns server  you had manually setup are the same that are in the lease the dhcp server is giving you.  Maybe to test you could change the dns servers to something completely different.  You can use the NetworkInterface class to check the dns servers.

    Here I wrote a little sample

                System.Net.NetworkInformation.NetworkInterface inet = NetworkInterface.GetAllNetworkInterfaces()[0];
                if (inet.GetIPProperties().IsDynamicDnsEnabled)
                {
                    Console.WriteLine("Using dns from dhcp server.");
                }
                IPAddressCollection col = inet.GetIPProperties().DnsAddresses;
                foreach (IPAddress address in col)
                {
                    Console.WriteLine(address);
                }
    • Marked as answer by Zhi-Xin Ye Monday, September 22, 2008 7:33 AM
    Wednesday, September 17, 2008 1:10 AM