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:
property IPAddressCollection^ DnsAddresses {
	virtual IPAddressCollection^ get() abstract;
}

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.

void DisplayDnsAddresses()
{
   array<NetworkInterface^>^adapters = NetworkInterface::GetAllNetworkInterfaces();
   System::Collections::IEnumerator^ myEnum11 = adapters->GetEnumerator();
   while ( myEnum11->MoveNext() )
   {
      NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum11->Current);
      IPInterfaceProperties ^ adapterProperties = adapter->GetIPProperties();
      IPAddressCollection ^ dnsServers = adapterProperties->DnsAddresses;
      if ( dnsServers->Count > 0 )
      {
         Console::WriteLine( adapter->Description );
         System::Collections::IEnumerator^ myEnum12 = dnsServers->GetEnumerator();
         while ( myEnum12->MoveNext() )
         {
            IPAddress ^ dns = safe_cast<IPAddress ^>(myEnum12->Current);
            Console::WriteLine( "  DNS Servers ............................. : {0}", 
               dns->ToString());
         }
      }
   }
}

.NET Framework
Available since 2.0
Return to top
Show: