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?
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!
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);
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With