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.


  • 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:
var MXs = JHSoftware.DnsClient.LookupMX("simpledns.com");
foreach (var MX in MXs)
   Console.WriteLine(MX.Preference + " " + MX.HostName);
   if (MX.IPAddresses != null)
      foreach (var IP in MX.IPAddresses)
         Console.WriteLine(">>> " + IP.ToString());
Lookup IPv4 addresses for www.simpledns.com using specific DNS servers:
var Options = new JHSoftware.DnsClient.RequestOptions();
Options.DnsServers = new System.Net.IPAddress[] { 
           System.Net.IPAddress.Parse("") };
var IPs = JHSoftware.DnsClient.LookupHost("www.simpledns.com", 
foreach(var IP in IPs)
Lookup SPF-records for simpledns.com (and check if DNS server offers recursion):
var Response = JHSoftware.DnsClient.Lookup("simpledns.com", 
Console.WriteLine("Recursion available: " + Response.RecursionAvailable);
foreach(var Record in Response.AnswerRecords) 
   Console.WriteLine(Record.Name + " " + 
                     Record.Type.ToString() + " " +
                     Record.TTL + " " +
Do asynchronous lookup for www.simpledns.com:
static void Main(string[] args)
   // do other stuff while waiting for lookup to complete...

static void MyCallback(IAsyncResult ar)
   var IPs = JHSoftware.DnsClient.EndLookupHost(ar);
   foreach (var IP in IPs)

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 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.

Be the first to comment on this page:
(Never published. Used for replies and to show your Gravatar icon. Never used for any other purpose.)