https://github.com/EvotecIT/DnsClientX
DnsClientX is an async C# library for DNS over UDP, TCP, HTTPS (DoH), and TLS (DoT). It also has a PowerShell module that can be used to query DNS records. It provides a simple way to query DNS records using multiple DNS providers. It supports multiple DNS record types and parallel queries.
https://github.com/EvotecIT/DnsClientX
dns dns-over-https dns-over-tcp dns-over-tls dns-over-udp dnsclient
Last synced: 5 months ago
JSON representation
DnsClientX is an async C# library for DNS over UDP, TCP, HTTPS (DoH), and TLS (DoT). It also has a PowerShell module that can be used to query DNS records. It provides a simple way to query DNS records using multiple DNS providers. It supports multiple DNS record types and parallel queries.
- Host: GitHub
- URL: https://github.com/EvotecIT/DnsClientX
- Owner: EvotecIT
- Created: 2024-03-09T17:49:55.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-19T17:47:24.000Z (6 months ago)
- Last Synced: 2024-10-29T21:06:10.619Z (6 months ago)
- Topics: dns, dns-over-https, dns-over-tcp, dns-over-tls, dns-over-udp, dnsclient
- Language: C#
- Homepage:
- Size: 4.54 MB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.MD
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- jimsghstars - EvotecIT/DnsClientX - DnsClientX is an async C# library for DNS over UDP, TCP, HTTPS (DoH), and TLS (DoT). It also has a PowerShell module that can be used to query DNS records. It provides a simple way to query DNS record (C# #)
README
# DnsClientX - DnsClient for .NET and PowerShell
DnsClientX is available as NuGet from the Nuget Gallery and as PowerShell module from PSGallery
## What it's all about
**DnsClientX** is an async C# library for DNS over UDP, TCP, HTTPS (DoH), and TLS (DoT). It also has a PowerShell module that can be used to query DNS records. It provides a simple way to query DNS records using multiple DNS providers. It supports multiple DNS record types and parallel queries. It's available for .NET 6, .NET 7, .NET 8, .NET Standard 2.0, and .NET 4.7.2.
It provides querying multiple DNS Providers.
- [Cloudflare](https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/)
- [Quad9](https://www.quad9.net/news/blog/doh-with-quad9-dns-servers/)
- OpenDNS
- etc.If you want to learn about DNS:
- https://www.cloudflare.com/learning/dns/what-is-dns/> [!WARNING]
> We try to unify the responses as much as possible for common use cases by translating on the fly. This is because different providers do not store it always the same way. If you find disprepencies please **open an issue** or better **pull request**.## Supported .NET Versions
This library supports multiple NET versions:
- .NET 6
- No dependencies
- .NET 7
- No dependencies
- .NET 8
- No dependencies
- .NET Standard 2.0
- System.Text.Json
- .NET 4.7.2
- System.Text.Json## Build Status
| Platform | Status | Test Report | Code Coverage | .NET |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| Windows ||
|
| .NET 4.7.2, NET 4.8, .NET 6.0, .NET 7.0, .NET 8.0, .NET Standard 2.0 |
| Linux ||
| | .NET 6.0, .NET 7.0, .NET Standard 2.0, .NET 8.0 |
| MacOs ||
| | .NET 6.0, .NET 7.0, .NET Standard 2.0, .NET 8.0 |
## Features- [x] Supports multiple built-in DNS Providers (System, Cloudflare, Google, Quad9, OpenDNS, etc.)
- [x] Supports both JSON and Wireformat
- [x] Supports DNS over HTTPS (DoH) using GET and POST methods
- [x] Supports DNS over TLS (DoT)
- [x] Supports DNS over UDP, and switches to TCP if needed
- [x] Supports DNS over TCP
- [x] Supports DNSSEC
- [x] Supports multiple DNS record types
- [x] Supports parallel queries
- [x] No external dependencies on .NET 6, .NET 7 and .NET 8
- [x] Minimal dependencies on .NET Standard 2.0 and .NET 4.7.2## TO DO
> [!IMPORTANT]
> This library is still in development and there are things that need to be done, tested and fixed.
> If you would like to help, please do so by opening an issue or a pull request.
> Things may and will change, as I'm not quite sure what I am doing :-)- [ ] [Add more providers](https://dnscrypt.info/public-servers/)
- [ ] Add more tests
- [ ] Go thru all additional parameters and make sure they have proper responses## Usage in .NET
There are multiple ways to use DnsClientX.
```csharp
using DnsClientX;
```Below are some examples.
### Querying DNS over HTTPS via provided hostname that uses /dns-query endpoint and JSON format
```csharp
var data = await ClientX.QueryDns("evotec.pl", DnsRecordType.A, "1.1.1.1", DnsRequestFormat.JSON);
data.Answers
```### Querying DNS over HTTPS via defined endpoint using QueryDns
```csharp
var data = await ClientX.QueryDns("evotec.pl", DnsRecordType.A, DnsEndpoint.CloudflareWireFormat);
data.Answers
```### Querying DNS over HTTPS via full Uri using QueryDNS and JSON format
```csharp
var data = await ClientX.QueryDns("evotec.pl", DnsRecordType.A, new Uri("https://1.1.1.1/dns-query"), DnsRequestFormat.JSON);
data.Answers
```### Querying DNS over HTTPS via defined endpoint using ResolveAll
```csharp
var Client = new ClientX(DnsEndpoint.OpenDNS);
var data = await Client.ResolveAll(domainName, type);
data
```### Querying DNS over HTTPS with single endpoint using ResolveAll
```csharp
var Client = new ClientX(DnsEndpoint.OpenDNS);
var data = await Client.ResolveAll(domainName, type);
data
```### Querying DNS over HTTPS with multiple endpoints using Resolve
```csharp
var dnsEndpoints = new List {
DnsEndpoint.Cloudflare,
DnsEndpoint.CloudflareSecurity,
DnsEndpoint.CloudflareFamily,
DnsEndpoint.CloudflareWireFormat,
DnsEndpoint.Google,
DnsEndpoint.Quad9,
DnsEndpoint.Quad9ECS,
DnsEndpoint.Quad9Unsecure,
DnsEndpoint.OpenDNS,
DnsEndpoint.OpenDNSFamily
};// List of endpoints to exclude
var excludeEndpoints = new List {};
var domains = new List {
"github.com",
"microsoft.com",
"evotec.xyz"
};// List of record types to query
var recordTypes = new List {
DnsRecordType.A,
DnsRecordType.TXT,
DnsRecordType.AAAA,
DnsRecordType.MX,
DnsRecordType.NS,
DnsRecordType.SOA,
DnsRecordType.DNSKEY,
DnsRecordType.NSEC
};foreach (var endpoint in dnsEndpoints) {
if (excludeEndpoints.Contains(endpoint)) {
continue; // Skip this iteration if the endpoint is in the exclude list
}// Create a new client for each endpoint
var client = new ClientX(endpoint) {
Debug = false
};foreach (var domain in domains) {
foreach (var recordType in recordTypes) {
DnsResponse? response = await client.Resolve(domain, recordType);
response.DisplayToConsole();
}
}
}
```## Usage in PowerShell
DnsClientX is also available as a PowerShell module. Below are some examples.
```powershell
Resolve-DnsQuery -Name 'evotec.pl' -Type A | Format-Table
Resolve-DnsQuery -Name 'evotec.pl' -Type A -DnsProvider Cloudflare -Verbose | Format-Table
Resolve-DnsQuery -Name 'evotec.pl' -Type TXT -DnsProvider System -Verbose | Format-Table
Resolve-DnsQuery -Name 'github.com', 'evotec.pl', 'google.com' -Type TXT -DnsProvider System -Verbose | Format-Table
```It can also deliver more detailed information.
```powershell
$Output = Resolve-DnsQuery -Name '_25._tcp.mail.ietf.org' -Type TLSA -DnsProvider Cloudflare -Verbose -FullResponse
$Output.Questions | Format-Table
$Output.AnswersMinimal | Format-Table$Output = Resolve-DnsQuery -Name 'github.com', 'evotec.pl', 'google.com' -Type TXT -DnsProvider Google -Verbose -FullResponse
$Output.Questions | Format-Table
$Output.AnswersMinimal | Format-Table$Output = Resolve-DnsQuery -Name 'github.com', 'evotec.pl', 'google.com' -Type TXT -DnsProvider Cloudflare -Verbose -FullResponse
$Output.Questions | Format-Table
$Output.AnswersMinimal | Format-Table$Output = Resolve-DnsQuery -Name 'github.com', 'evotec.pl', 'google.com' -Type TXT, A -Verbose -Server "192.168.241.5" -FullResponse
$Output.Questions | Format-Table
$Output.AnswersMinimal | Format-Table
```## Please share with the community
Please consider sharing a post about DnsClientX and the value it provides. It really does help!
[](https://reddit.com/submit?url=https://github.com/EvotecIT/DnsClientX&title=DnsClientX)
[](https://news.ycombinator.com/submitlink?u=https://github.com/EvotecIT/DnsClientX)
[](https://twitter.com/share?url=https://github.com/EvotecIT/DnsClientX&t=DnsClientX)
[](https://www.facebook.com/sharer/sharer.php?u=https://github.com/EvotecIT/DnsClientX)
[](https://www.linkedin.com/shareArticle?url=https://github.com/EvotecIT/DnsClientX&title=DnsClientX)## Credits
This project general idea is based on [DnsOverHttps](https://github.com/actually-akac/DnsOverHttps) by [@akac](https://github.com/actually-akac) which was an inspiration for **DnsClientX**.
## Other libraries
- [DnsClient.NET](https://github.com/MichaCo/DnsClient.NET) - DnsClient is a simple yet very powerful and high performant open source library for the .NET Framework to do DNS lookups. If you need standard DNS support - this one is for you.
- [DnsOverHttps](https://github.com/actually-akac/DnsOverHttps) - DnsOverHttps is a simple yet very powerful and high performant open source library for the .NET Framework to do DNS lookups over HTTPS using Cloudflare. If you only need Cloudflare support and target newer .NET versions - this one is for you.
- [DinoDNS](https://github.com/TurnerSoftware/DinoDNS) - another DNS library with a lot of features.