Heijden.DNS.Resolver.GetDnsServers C# (CSharp) Method

GetDnsServers() public static method

Gets a list of default DNS servers used on the Windows machine.
public static GetDnsServers ( ) : System.Net.IPEndPoint[]
return System.Net.IPEndPoint[]
        public static IPEndPoint[] GetDnsServers()
        {
            List<IPEndPoint> list = new List<IPEndPoint>();

            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface n in adapters)
            {
                if (n.OperationalStatus == OperationalStatus.Up)
                {
                    IPInterfaceProperties ipProps = n.GetIPProperties();
                    foreach (IPAddress ipAddr in ipProps.DnsAddresses)
                        if (ipAddr.AddressFamily == AddressFamily.InterNetwork)
                        {
                            list.Add(new IPEndPoint(ipAddr, DefaultPort));
                        }
                }
            }
            return list.ToArray();
        }