API Documentation: https://alanedwardes.github.io/docs/Ae.Dns/
A pure C# implementation of a DNS client, server and configurable caching/filtering layer. This project offers the following packages:
Offers both HTTP(S) and UDP DNS clients, with a simple random client implementation.
This example is a very simple setup of the DnsHttpClient
using the CloudFlare DNS over HTTPS resolver.
See samples/BasicHttpClient/Program.cs
This example uses Microsoft.Extensions.Http.Polly
to allow retrying of failed requests.
See samples/AdvancedHttpClient/Program.cs
This example is a basic setup of the DnsUdpClient
using the primary CloudFlare UDP resolver.
See samples/BasicUdpClient/Program.cs
This example uses multiple upstream IDnsClient
implementations in a random fashion using DnsRandomClient
. Note that multiple protocols can be mixed, both the DnsUdpClient
and DnsHttpClient
can be used here since they implement IDnsClient
.
See samples/RandomClient/Program.cs
This example uses multiple (two or more) upstream IDnsClient
implementations and races them using DnsRacerClient
. Two queries are sent in parallel, and the fastest result "wins" (is returned). If a query faults, the other query result is used. As with the random client, multiple protocols can be mixed, both the DnsUdpClient
and DnsHttpClient
can be used here since they implement IDnsClient
.
See samples/RacerClient/Program.cs
This example uses the DnsCachingClient
to cache queries into a MemoryCache
, so that the answer is not retrieved from the upstream if the answer is within its TTL. Note that this can be combined with the DnsRandomClient
, so the cache can be backed by multiple upstream clients (it just accepts IDnsClient
).
See samples/CachingClient/Program.cs
Offers a standard DNS UDP server.
A example UDP server which forwards all queries via UDP to the CloudFlare DNS resolver, and blocks www.google.com
.
See samples/BasicUdpServer/Program.cs
A more advanced UDP server which uses the DnsCachingClient
and DnsRandomClient
to cache DNS answers from multiple upstream clients, and the RemoteSetFilter
to block domains from a remote hosts file.
See samples/AdvancedUdpServer/Program.cs
Offers an HTTPS (DoH) server for use with clients supporting the DNS over HTTPS protocol.
See samples/BasicHttpServer/Program.cs
Provides the low-level protocol handling for the over-the-wire DNS protocol format as per RFC 1035.
This package includes a DelegatingHandler
for HttpClient
which intercepts HTTP requests before they're sent across the wire, resolves the host with the specified IDnsClient
, replaces the host with one of the resolved IP addresses, then sends the request to the IP address with the host as the Host
header.
See samples/BasicHttpClientMiddleware/Program.cs