Class DnsClient
A minimal DNS client for TXT record lookup (RFC 1035). Supports UDP transport with TCP fallback for truncated responses, configurable query timeout, and multiple nameservers.
Inherited Members
Namespace: DRIT.Mail.Rfc.Net
Assembly: DRIT.Mail.dll
Syntax
public sealed class DnsClient
Constructors
View SourceDnsClient()
Initializes a new instance of the DnsClient class with a default 5-second query timeout.
Declaration
public DnsClient()
DnsClient(TimeSpan)
Initializes a new instance of the DnsClient class with the specified query timeout.
Declaration
public DnsClient(TimeSpan queryTimeout)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | queryTimeout | The timeout for each DNS query attempt. |
Methods
View SourceResolveTxtRecords(string)
Resolves TXT records for the given domain name using the system's configured DNS nameservers.
Declaration
public IReadOnlyList<string> ResolveTxtRecords(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The domain name to query (e.g., "selector._domainkey.example.com"). |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> | A list of TXT record values. Each entry is the concatenated character-string value of one TXT record in the answer section. Returns an empty list if no TXT records are found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| DnsException | Thrown if the query fails on all nameservers (timeout, network error, or server failure). |
ResolveTxtRecords(string, params string[])
Resolves TXT records for the given domain name using the specified nameservers. Nameservers are tried in order; the first to return a definitive answer is used.
Declaration
public IReadOnlyList<string> ResolveTxtRecords(string name, params string[] nameservers)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The domain name to query. |
| string[] | nameservers | IPv4 or IPv6 addresses of DNS nameservers to query, in preference order. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> | A list of TXT record values. Returns an empty list if the name exists but has no TXT records, or if the name does not exist (NXDOMAIN). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentException | Thrown if |
| DnsException | Thrown if all nameservers fail to respond. |