Get Dns Server : DNS « Network « C# / C Sharp






Get Dns Server

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Management;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;


class Utility
{
    public static String[] GetDnsServer()
    {
        ArrayList Servers = new ArrayList();

        foreach (NetworkInterface Nic in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (Nic.OperationalStatus == OperationalStatus.Up & Nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
            {
                IPInterfaceProperties NicProperties = Nic.GetIPProperties();
                foreach (IPAddress DnsAddress in NicProperties.DnsAddresses)
                {
                    Servers.Add(DnsAddress.ToString());
                }
            }
        }
        return (string[])Servers.ToArray(typeof(string));
    }

}

   
  








Related examples in the same category

1.DNS Reverse Lookup and Lookup
2.DNS Name Resolution
3.DNS Get Host By NameDNS Get Host By Name
4.Find DNS Servers
5.Get Resolve Info:DNSGet Resolve Info:DNS
6.Get DNS Host InfoGet DNS Host Info
7.Get DNS Address Info
8.DNS Address ResolverDNS Address Resolver
9.Find DNS Servers from Registry