Getting the DNS servers with .NET without WMI

Someone pointed me at System.Net.NetworkInformation, which has a lot of interesting objects.

You don’t have to use strings and query the WMI at runtime, which means you get compile time checking!

using System;
using System.Net;
using System.Net.NetworkInformation;

namespace WMITest
{
    internal class Program
    {
        public static int Main(string[] args)
        {
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                IPInterfaceProperties properties = adapter.GetIPProperties();

                foreach (IPAddress dnsServer in properties.DnsAddresses)
                {
                    Console.WriteLine("{0} ", dnsServer);
                }

                Console.WriteLine("----------------------");
            }

            Console.ReadLine();
            return 0;
        }
    }
}

Hope it helps :)