![]() |
VOOZH | about |
dotnet add package DNS --version 7.0.0
NuGet\Install-Package DNS -Version 7.0.0
<PackageReference Include="DNS" Version="7.0.0" />
<PackageVersion Include="DNS" Version="7.0.0" />Directory.Packages.props
<PackageReference Include="DNS" />Project file
paket add DNS --version 7.0.0
#r "nuget: DNS, 7.0.0"
#:package DNS@7.0.0
#addin nuget:?package=DNS&version=7.0.0Install as a Cake Addin
#tool nuget:?package=DNS&version=7.0.0Install as a Cake Tool
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("8.8.8.8"), 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
Console.WriteLine(response);
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("8.8.8.8");
// 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)
.Cast<IPAddressResourceRecord>()
.Select(r => r.IPAddress)
.ToList();
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("8.8.8.8");
// Create request bound to 8.8.8.8
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("173.194.69.100");
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, "8.8.8.8");
// Resolve these domain to localhost
masterFile.AddIPAddressResourceRecord("google.com", "127.0.0.1");
masterFile.AddIPAddressResourceRecord("github.com", "127.0.0.1");
// 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.
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("127.0.0.1"));
response.AnswerRecords.Add(record);
}
}
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 Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on DNS:
| Package | Downloads |
|---|---|
|
AtlasSSH
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. |
|
|
Neon.Kube
INTERNAL USE ONLY: Common library used by neonKUBE related projects. |
|
|
Blockcore.Features.Dns
Blockcore Features Dns |
|
|
Stratis.Features.Dns
Stratis Bitcoin Features Dns |
|
|
LibPacketGremlin
Library for manipulating packets |
Showing the top 9 popular GitHub repositories that depend on DNS:
| Repository | Stars |
|---|---|
|
BeyondDimension/SteamTools
🛠「Watt Toolkit」是一个开源跨平台的多功能 Steam 工具箱。
|
|
|
odedshimon/BruteShark
Network Analysis Tool
|
|
|
microsoft/WhatTheHack
A collection of challenge based hack-a-thons including student guide, coach guide, lecture presentations, sample/instructional code and templates. Please visit the What The Hack website at: https://aka.ms/wth
|
|
|
creazyboyone/FastGithub
FastGithub 是 GitHub 加速神器,解决 GitHub 打不开、用户头像无法加载、releases 无法上传下载、git-clone、git-pull、git-push
|
|
|
stratisproject/StratisBitcoinFullNode
Bitcoin full node in C#
|
|
|
shiftwinting/FastGithub
github定制版的dns服务,解析访问github最快的ip
|
|
|
Kooboo/Kooboo
CMS, WebSite, Application and Ecommerce Development Tool Using JavaScript
|
|
|
block-core/blockcore
Open source .NET Core Bitcoin based blockchain node in C#
|
|
|
Kengxxiao/CelestiteLauncher
Cross platform third-party DMM Game Player in C#
|