Skip to content

DnsClient.NET is a simple yet very powerful and high performant open source library for the .NET Framework to do DNS lookups

License

Notifications You must be signed in to change notification settings

positiwise/DnsClient.NET

 
 

Repository files navigation

Forked because of working on specific DNSSEC issues.

--Original Below---

DnsClient.NET

Build Status Code Coverage NuGet NuGet

DnsClient.NET is a simple yet very powerful and high performance open source library for the .NET Framework to do DNS lookups.

Usage

See http://dnsclient.michaco.net for more details and documentation.

The following example instantiates a new LookupClient to query some IP address.

var lookup = new LookupClient();
var result = await lookup.QueryAsync("google.com", QueryType.A);

var record = result.Answers.ARecords().FirstOrDefault();
var ip = record?.Address;

Features

General

  • Sync & Async API
  • UDP and TCP lookup, configurable if TCP should be used as fallback in case the UDP result is truncated (default=true).
  • Configurable EDNS support to change the default UDP buffer size and request security relevant records
  • Caching
    • Query result cache based on provided TTL
    • Minimum TTL setting to overrule the result's TTL and always cache the responses for at least that time. (Even very low value, like a few milliseconds, do make a huge difference if used in high traffic low latency scenarios)
    • Maximum TTL to limit cache duration
    • Cache can be disabled
  • Multiple DNS endpoints can be configured. DnsClient will use them in random or sequential order (configurable), with re-tries.
  • Configurable retry of queries
  • Optional audit trail of each response and exception
  • Configurable error handling. Throwing DNS errors, like NotExistentDomain is turned off by default
  • Optional Trace/Logging

Supported resource records

  • A, AAAA, NS, CNAME, SOA, MB, MG, MR, WKS, HINFO, MINFO, MX, RP, TXT, AFSDB, URI, CAA, NULL, SSHFP, TLSA, RRSIG, NSEC, DNSKEY, DS
  • PTR for reverse lookups
  • SRV for service discovery. LookupClient has some extensions to help with that.
  • AXFR zone transfer (as per spec, LookupClient has to be set to TCP mode only for this type. Also, the result depends on if the DNS server trusts your current connection)

Build from Source

The solution requires a .NET Core 3.x SDK and the .NET 4.7.1 Dev Pack being installed.

Just clone the repository and open the solution in Visual Studio 2017/2019.

The unit tests don't require any additional setup right now.

If you want to test the different record types, there are config files for Bind under tools. Just download Bind for Windows and copy the binaries to tools/BIND, then run bind.cmd. If you are running this on Linux, you can use my config files and replace the default ones if you want.

Now, you can use samples/MiniDig to query the local DNS server. The following should return many different resource records:

dotnet run -s localhost mcnet.com any

Examples

About

DnsClient.NET is a simple yet very powerful and high performant open source library for the .NET Framework to do DNS lookups

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%