Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query DNS using specific DNS servers in .NET

Tags:

.net

dns

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?

like image 682
Philippe Leybaert Avatar asked Oct 14 '09 08:10

Philippe Leybaert


3 Answers

Although this is a pretty old question. There are still new libraries being developed to do this as the .NET Framework still does not have support for this ;)

Have a look at http://dnsclient.michaco.net. It is easy to use, high performant and open source!

And it works on .NET Core cross platform, too!

like image 195
MichaC Avatar answered Oct 19 '22 07:10

MichaC


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);
            }
        }
like image 38
armannvg Avatar answered Oct 19 '22 05:10

armannvg


You can do this with "JH Software's DNS Client for .NET". See the second code sample at http://www.simpledns.com/dns-client-lib.aspx

like image 36
Jesper Avatar answered Oct 19 '22 05:10

Jesper