Simple DNS Plus
menubar Skip Navigation Links
Home
Product Details
Download
Purchase
Support
Company
menubar

DNS Client Library for .NET

This library (JH Software's DNS Client Library for .NET) is a freeware component that can be used to perform simple as well as advanced DNS lookups from any .NET code (.NET v. 2.0 or later) against any standard based DNS server.

The .NET framework system.Net.Dns class does provide methods to do basic forward and reverse DNS lookups (host name to IP address / IP address to host name), but it cannot lookup other record types (such as MX-records to locate e-mail servers), it does not allow you to specify which DNS servers to use or specify any options for how the lookup is performed, and it does not give you access to any of the DNS response flags and additional data.
This library fixes all that and more.

Features

  • Lookup any DNS record type (A, AAAA, MX, SPF, SOA, SRV, etc.).
  • Optionally specify which DNS servers to query (default = DNS servers from local system config).
  • Optionally use EDNS0 / specify payload size (more efficient lookups with UDP packets larger than 512 bytes).
  • Optionally use DNS-0x20 (protect against Kaminsky bug / DNS spoofing).
  • Specify whether to request recursion or not (RD flag).
  • Specify request timeout and retry count.
  • Specify which port number to send queries to (default = 53).
  • Access to response details including responding server IP address, AA-flag (authoritative answer), RA-flag (recursion available), EDNS0, as well as individual DNS records (name, type, TTL, data) in answer, authority, and additional sections.
  • Synchronous and asynchronous (Begin.../End...) lookup methods.
  • Works with both IPv4 and IPv6 DNS servers.
  • Automatically switches from UDP to TCP when receiving truncated responses (TC flag).
  • Always uses random query ID and UDP origin port number (protect against Kaminsky bug / DNS spoofing).
  • Fully documented including intellisense in Visual Studio.
  • Convenient simplified methods for host (A/AAAA), reverse (PTR), and MX lookups.
  • Functions to encode/decode IDNs (Internationalized Domain Names).
  • Built on program code from Simple DNS Plus - tested by thousands of users for +10 years.
  • Freeware (see license terms below).

Programming Overview

The primary functions in this library are Lookup, LookupHost, LookupReverse, and LookupMX - all static methods of JHSoftware.DnsClient. Each of these functions have several of overloads, and each has an asynchronous version (Begin... / End...). The LookupHost, LookupReverse, LookupMX functions are used to lookup specific types of DNS records and only return basic data. The Lookup function can lookup any DNS record type and returns a detailed Response object.
For more details, see the help file - also included as a .chm file in the download.

Code Samples

Lookup e-mail servers (MX) for simpledns.com: VB.NET  C#
Dim MXs = JHSoftware.DnsClient.LookupMX("simpledns.com")
For Each MX In MXs
   Console.WriteLine(MX.Preference & " " & MX.HostName)
   If MX.IPAddresses IsNot Nothing Then
      For Each IP In MX.IPAddresses
         Console.WriteLine(">>> " & IP.ToString())
      Next
   End If
Next
Lookup IPv4 addresses for www.simpledns.com using specific DNS servers: VB.NET  C#
Dim Options = New JHSoftware.DnsClient.RequestOptions
Options.DnsServers = New System.Net.IPAddress() { _
               System.Net.IPAddress.Parse("1.1.1.1"), _
               System.Net.IPAddress.Parse("2.2.2.2")}
Dim IPs = JHSoftware.DnsClient.LookupHost("www.simpledns.com", _
                                          JHSoftware.DnsClient.IPVersion.IPv4, _
                                          Options)
For Each IP In IPs
   Console.WriteLine(IP.ToString)
Next
Lookup SPF-records for simpledns.com (and check if DNS server offers recursion): VB.NET  C#
Dim Response = JHSoftware.DnsClient.Lookup("simpledns.com", _
                                           JHSoftware.DnsClient.RecordType.SPF)
Console.WriteLine("Recursion available: " & Response.RecursionAvailable)
For Each Record In Response.AnswerRecords
   Console.WriteLine(Record.Name & " " & _
                     Record.Type.ToString & " " & _
                     Record.TTL & " " & _
                     Record.Data)
Next
Do asynchronous lookup for www.simpledns.com: VB.NET  C#
Sub Main()
   JHSoftware.DnsClient.BeginLookupHost("www.simpledns.com", _
                                        JHSoftware.DnsClient.IPVersion.IPv4, _
                                        Nothing, _
                                        AddressOf MyCallback, _
                                        Nothing)
   REM do other stuff while waiting for lookup to complete...
   Console.ReadKey()
End Sub

Sub MyCallback(ByVal ar As IAsyncResult)
   Dim IPs = JHSoftware.DnsClient.EndLookupHost(ar)
   For Each IP In IPs
      Console.WriteLine(IP.ToString)
   Next
End Sub

License Terms

This software is provided to you free of charge (freeware). You may not reverse engineer it or pass it on as your own as your own creation, but otherwise you are free to use it, include it with other products and services, and distribute it through any media in any way you like. We would of course appreciate a link back to this page page, and/or to be mentioned in the credits of whatever you use it for, but neither is required.

Download

Download JH Software's DNS Client Library for .NET v. 1.0 build 1 (October 29th 2009):

Download JHSoftware.DnsClient.zip (269 KB)

Release Notes

Version 1.0 build 1 - October 29th 2009
- First release.

comments powered by Disqus

Comments from before we implemented Disqus:

15 Apr 2014 12:40 GMT - by Onur:
@JHSoftware
Thanks for the response sir, i've just figured it out. It requires a seperate object instantiation to query each seperate DNS.
Cheers.

15 Apr 2014 10:35 GMT - by Jesper - JH Software:
Hi Onur,
when specifying multiple DNS servers, the 2nd, 3rd, etc. DNS servers are only used if the previous ones do not respond.
If you want know the response from a specific DNS server, you should only specify that one DNS server IP address, and then do another separate request against the other DNS server.

12 Apr 2014 07:58 GMT - by Onur:
Additionaly, i want to get each IP response seperately for each DNS server to compare results. Is it possible like running bunch of nslookup commands manually?

12 Apr 2014 07:44 GMT - by Onur:
Hi,
Used the code snippet above titled as "Lookup IPv4 addresses for www.simpledns.com using specific DNS servers", and as in the snippet i specified 2 different DNS addresses, queried but the for-each did NOT result seperated for each 2 DNS servers. I only get ONE bunch of IP-result as if i'm querying only for one DNS server. The results are the same in fact, is the library grouping same DNS addresses implicty? What should i do to get results seperately for each DNS added by Parse method?
Why is this?

24 Jan 2014 13:43 GMT - by Maximus:
YOU ARE THE BEST BRO, LOOKING FOR AGES FOR SOMETHING LIKE THIS !!!!! MAN I LOVE YOU !!!! YOU ARE THE BEST!!!!!

03 Sep 2013 10:37 GMT - by Mahesh:
Excellent code.. Thank you very much

06 Sep 2012 20:52 GMT - by Gareth Jenkins:
Hi Jesper
Wondering if there was any chance of an update to this component so that the LookupMX() method also returns the TTL within the MXHost returned data. I know I can get this using the Lookup() method, but this then does not sort by preference, which is a very useful feature.
Many thanks for making a great tool!

02 Apr 2012 15:40 GMT - by John:
Hi Jesper,
Great code. Quick question. It is possible for a next release to be able to specify the source IP you can bind on the DNS client?
Thanks

23 Mar 2012 21:02 GMT - by David:
Hi,
Thanks for the reply.
The SPF is the one that's not working. I've been using the same code (except for ....RecordType.SPF).
It returns:
JHSoftware.DnsClient+NoDefinitiveAnswerException: None of the DNS servers returned a definitive response. See the ServerProblem property for individual DNS server problems. at JHSoftware.DnsClient.EndLookup(IAsyncResult asyncResult) at JHSoftware.DnsClient.Lookup(String domainName, RecordType queryType, RequestOptions options) at OurDomain.spf_record.btnSubmit_Click(Object sender, EventArgs e) in C:\Projects\Ourproject\CudaMail-2011\tools\spf-record.aspx.vb:line 29
- now, I happen to know that the domain we're checking (another one of ours) definitely has an spf record which we check with other tools.
I wonder if any of the experts here can see what I'm doing wrong?
Thanks in advance.

17 Mar 2012 11:46 GMT - by Jesper - JH Software:
Hi David,
If you use the generic "Lookup" method for both types (for MX-records, you can also use the "LookupMX" method which has a different return type) - then yes you will have the same fields.
Of course the "data" field for each record will looku different for each record type.

16 Mar 2012 19:41 GMT - by David:
Hi,
The code above for SPF lookup lists the same fields as the MX record (name, type, ttl, data). Is that correct? I have it working fine for MX records but the spf record doesn't seem to be pulling the SPF properly.
thanks

17 May 2011 08:20 GMT - by KickStart64:
Any luck with a .net 4.0 compile ? Btw, why don't you guys release the code ? You are giving away the DLL why not the code as well ??

18 Mar 2011 18:15 GMT - by Jesper - JH Software:
Above library is compiled for "AnyCPU" and should work fine with both 32 and 64 bit applications, web-sites, etc.
And while not compiled specifically for .NET 4.0, you should still be able to use it with .NET 4.0 as long as .NET 2.0 is also available.
I expect we will release a .NET 4.0 version at some point, but we don't have a build environment in place for that at this time.

18 Mar 2011 14:47 GMT - by Marc:
So, I'm guessing this is abandonware? Does anyone monitor these?

07 Oct 2010 16:54 GMT - by mike g:
64 bit .net 4.0 would be amazing... something I'd pay for .. any chance?

23 Sep 2010 14:12 GMT - by Marc:
Any chance of a 64-bit compiled version for .net 4.0 (or source...)?

03 Sep 2010 00:38 GMT - by petersonwilliams:
thanks for the release of idea to aid it's required personnesl like me . kudos ..................................


Copyright © 1999-2014 JH Software ApS. All Rights Reserved.
E-mail questions to
Terms of Use | Privacy Statement | Return Policy | About Us
help index