Monday, August 23, 2010

Retrieving configured DNS servers across all network adapters

   1:  Dim dnsAddressList As IPAddressCollection = Nothing
   2:   
   3:  For Each adapter In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
   4:   
   5:      Dim adapterProperties = adapter.GetIPProperties()
   6:      Dim dnsServers As IPAddressCollection = adapterProperties.DnsAddresses
   7:      If dnsAddressList Is Nothing Then
   8:      dnsAddressList = dnsServers
   9:      Else
  10:      dnsAddressList.Union(dnsServers)
  11:      End If
  12:  Next adapter
  13:   
  14:  Return dnsAddressList

No comments: