Query DNS using specific DNS servers in .NET

.net, dns

Solution

You could also take a look at opendns.net and check if it fits your application

Here is some example code to get you started:

        var query = new DnsQuery();

        query.Servers.Add("ns1.domainname.com");
        query.Servers.Add("ns2.domainname.com");
        query.Servers.Add("ns3.domainname.com");

        query.Domain = "domain.com";

        query.QueryType = Types.TXT;

        if (query.Send())
        {
            Console.WriteLine("TXT:");
            var response = query.Response;
            foreach (ResourceRecord answer in response.Answers)
            {
                Console.WriteLine(answer.RText);
            }
        }

        query.QueryType = OpenDNS.Types.MX;

        if (query.Send())
        {
            Console.WriteLine("MX:");
            var response = query.Response;
            foreach (MX answer in response.Answers)
            {
                Console.WriteLine("{0} {1}", answer.Preference, answer.Exchange);
            }
        }

Problem

From a .NET application, I need to query a specific DNS server for resolving a domain name (the DNS server is not defined in the Windows network configuration). I know this is not possible using standard .NET Framework classes (See this other question). My question is what my options are. There is one open source library on CodePlex (DnDns) which does that, but it hasn't been updated in a long time, and my application is mission-critical so reliability is extremely important. Any suggestions?

Original source

Related problems