DNS 7.0.0

.NET Standard 2.0
Install-Package DNS -Version 7.0.0
dotnet add package DNS --version 7.0.0
<PackageReference Include="DNS" Version="7.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DNS --version 7.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DNS, 7.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install DNS as a Cake Addin
#addin nuget:?package=DNS&version=7.0.0

// Install DNS as a Cake Tool
#tool nuget:?package=DNS&version=7.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.


A DNS library written in C# targeting .NET Standard 2.0. Versions prior to version two (2.0.0) were written for .NET 4 using blocking network operations. Version two and above use asynchronous operations.

Available through NuGet.

Install-Package DNS



The library exposes a Request and Response classes for parsing and creating DNS messages. These can be serialized to byte arrays.

Request request = new Request();

request.RecursionDesired = true;
request.Id = 123;

UdpClient udp = new UdpClient();
IPEndPoint google = new IPEndPoint(IPAddress.Parse(""), 53);

// Send to google's DNS server
await udp.SendAsync(request.ToArray(), request.Size, google);

UdpReceiveResult result = await udp.ReceiveAsync();
byte[] buffer = result.Buffer;
Response response = Response.FromArray(buffer);

// Outputs a human readable representation


The libray also includes a small client and a proxy server. Using the ClientRequest or the DnsClient class it is possible to send a request to a Domain Name Server. The request is first sent using UDP, if that fails (response is truncated), the request is sent again using TCP. This behaviour can be changed by supplying an IRequestResolver to the client constructor.

ClientRequest request = new ClientRequest("");

// Request an IPv6 record for the foo.com domain
request.Questions.Add(new Question(Domain.FromString("foo.com"), RecordType.AAAA));
request.RecursionDesired = true;

ClientResponse response = await request.Resolve();

// Get all the IPs for the foo.com domain
IList<IPAddress> ips = response.AnswerRecords
	.Where(r => r.Type == RecordType.AAAA)
	.Select(r => r.IPAddress)

The DnsClient class contains some conveniance methods for creating instances of ClientRequest and resolving domains.

// Bind to a Domain Name Server
DnsClient client = new DnsClient("");

// Create request bound to
ClientRequest request = client.Create();

// Returns a list of IPs
IList<IPAddress> ips = await client.Lookup("foo.com");

// Get the domain name belonging to the IP (google.com)
string domain = await client.Reverse("");


The DnsServer class exposes a proxy Domain Name Server (UDP only). You can intercept domain name resolution requests and route them to specified IPs. The server is asynchronous. It also emits an event on every request and every successful resolution.

// Proxy to google's DNS
MasterFile masterFile = new MasterFile();
DnsServer server = new DnsServer(masterFile, "");

// Resolve these domain to localhost
masterFile.AddIPAddressResourceRecord("google.com", "");
masterFile.AddIPAddressResourceRecord("github.com", "");

// Log every request
server.Requested += (sender, e) => Console.WriteLine(e.Request);
// On every successful request log the request and the response
server.Responded += (sender, e) => Console.WriteLine("{0} => {1}", e.Request, e.Response);
// Log errors
server.Errored += (sender, e) => Console.WriteLine(e.Exception.Message);

// Start the server (by default it listens on port 53)
await server.Listen();

Depending on the application setup the events might be executed on a different thread than the calling thread.

It's also possible to modify the request instance in the server.Requested callback.

Request Resolver

The DnsServer, DnsClient and ClientRequest classes also accept an instance implementing the IRequestResolver interface, which they internally use to resolve DNS requests. Some of the default implementations are UdpRequestResolver, TcpRequestResolver and MasterFile classes. But it's also possible to provide a custom request resolver.

// A request resolver that resolves all dns queries to localhost
public class LocalRequestResolver : IRequestResolver {
	public Task<IResponse> Resolve(IRequest request) {
		IResponse response = Response.FromRequest(request);

		foreach (Question question in response.Questions) {
			if (question.Type == RecordType.A) {
				IResourceRecord record = new IPAddressResourceRecord(
					question.Name, IPAddress.Parse(""));

		return Task.FromResult(response);

// All dns requests received will be handled by the localhost request resolver
DnsServer server = new DnsServer(new LocalRequestResolver());

await server.Listen();
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on DNS:

Package Downloads

Allows user to download datasets from the GRID and run jobs on the GRID. Geared towards use at ATLAS, but no reason it can't be adapted for other experiments.


Blockcore Features Dns


Library for manipulating packets


Stratis Bitcoin Features Dns


Measure dnscrypt-proxy resolvers

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on DNS:

Repository Stars
Network Analysis Tool
Bitcoin full node in C#
Open source .NET Core Bitcoin based blockchain node in C#
Version Downloads Last updated
7.0.0 13,263 11/28/2021
6.1.0 58,436 9/7/2020
6.0.1 1,381 8/30/2020
6.0.0 29,252 3/13/2020
5.0.0 116,972 9/22/2018
4.1.0 1,110 9/22/2018
4.0.0 13,417 4/5/2018
3.0.0 5,309 1/5/2018
2.1.0 49,522 6/19/2017
2.0.1 1,010 5/13/2017
2.0.0 1,800 4/17/2017
1.2.3 16,435 9/19/2016
1.2.2 9,412 11/11/2015
1.2.1 2,274 9/29/2015
1.2.0 1,269 9/20/2015
1.0.1 1,624 9/22/2014
1.0.0 1,353 9/22/2014