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

xudonax/DnsClient.NET

 
 

Repository files navigation

DnsClient.NET

DnsClient.NET is a simple yet very powerful and high performant 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 without specifying a DNS endpoint. DnsClient.NET will query your system network adapters to determine available DNS servers.

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

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

Builds

Build status

Get it via NuGet https://www.nuget.org/packages/DnsClient/

Get beta builds from MyGet.

Build from Code

Just clone the repository and open the solution in Visual Studio 2017. Or use the dotnet client via command line.

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 micha.mcnet.com any

To test some random domain names, run MiniDig with the random sub command (works without setting up Bind, too).

dotnet run random -s localhost

Features

General

  • Full Async API
  • UDP and TCP lookup, configurable if TCP should be used as fallback in case UDP result is truncated (default=true).
  • 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)
    • Cache can be disabled altogether
  • Supports multiple DNS endpoints to be configured
  • Configurable retry over configured DNS servers if one or more returned a server error
  • Configurable retry logic in case of timeouts and other exceptions
  • Optional audit trail of each response and exception
  • Configurable error handling. Throwing DNS errors, like NotExistentDomain is turned off by default

Supported resource records

  • PTR for reverse lookups
  • A, AAAA, NS, CNAME, SOA, MB, MG, MR, WKS, HINFO, MINFO, MX, RP, TXT, AFSDB, SRV, URI, CAA
  • OPT (currently only for reading the supported UDP buffer size, EDNS version)
  • AXFR (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)

Examples

  • The Samples repository will have some solutions to showcase the usage and also to test some functionality.

  • MiniDig (See the readme over there)

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# 97.9%
  • HTML 2.1%