IPInterfaceProperties.DnsAddresses Property

Gets the addresses of Domain Name System (DNS) servers for this interface.

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)

public abstract IPAddressCollection DnsAddresses { get; }

Property Value

Type: System.Net.NetworkInformation.IPAddressCollection
A IPAddressCollection that contains the DNS server addresses.

DNS is a hierarchical naming system used to map host names to IP addresses.

The following code example displays the DNS addresses for the network interfaces on the local computer.

public static void DisplayDnsAddresses()
{
    NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {

        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        IPAddressCollection dnsServers = adapterProperties.DnsAddresses;
        if (dnsServers.Count > 0)
        {
            Console.WriteLine(adapter.Description);
            foreach (IPAddress dns in dnsServers)
            {
                Console.WriteLine("  DNS Servers ............................. : {0}", 
                    dns.ToString());
            }
            Console.WriteLine();
        }
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft