Class Resolver
Represents a DNS resolver that performs DNS queries and manages response caching with support for customizable transport protocols and query configurations.
public class Resolver
- Inheritance
-
Resolver
- Inherited Members
Properties
Recursion
Gets a value indicating whether DNS recursion is enabled for the resolver. When enabled, recursive DNS queries are performed, allowing the resolver to fetch complete DNS responses.
public bool Recursion { get; init; }
Property Value
Retries
Gets or initializes the number of retry attempts for DNS queries in case of failure.
public int Retries { get; init; }
Property Value
Timeout
Gets or initializes the timeout duration, in milliseconds, for DNS queries. This value determines how long the resolver waits for a response before timing out.
public int Timeout { get; init; }
Property Value
TransportType
Gets or sets the transport protocol used for DNS queries. Determines whether queries are sent over UDP or TCP.
public TransportType TransportType { get; set; }
Property Value
UseCache
Gets a value indicating whether the DNS resolver should use caching for responses.
When set to false, the existing cache is cleared.
public bool UseCache { get; init; }
Property Value
Version
Gets the version information for the current assembly.
public static string? Version { get; }
Property Value
Methods
ClearCache()
Clears all entries in the DNS response cache.
public void ClearCache()
GetArpaFromEnumerator(string)
Converts an enumerator string to its corresponding ARPA address.
public static string GetArpaFromEnumerator(string enumerator)
Parameters
enumeratorstringThe enumerator representing a numerical address to convert.
Returns
- string
The resulting ARPA address as a string.
GetArpaFromIp(IPAddress)
Converts the given IP address into its corresponding reverse DNS ARPA address.
public static string GetArpaFromIp(IPAddress ip)
Parameters
ipIPAddressThe IP address to be converted into an ARPA address.
Returns
- string
A string representing the reverse DNS ARPA address for the provided IP address. If the address family is unsupported, returns "?".
Query(string, QuestionType, QuestionClass)
Sends a DNS query for the specified domain name, question type, and question class.
public Response Query(string domainName, QuestionType questionType, QuestionClass questionClass = QuestionClass.IN)
Parameters
domainNamestringThe domain name to resolve.
questionTypeQuestionTypeThe type of DNS query (e.g., A, AAAA, MX).
questionClassQuestionClassThe class of DNS query (e.g., IN for Internet).
Returns
Exceptions
- InvalidOperationException
The resolver has no DNS servers configured.
QueryAsync(string, QuestionType, CancellationToken)
Sends a DNS query asynchronously in the internet class.
public Task<Response> QueryAsync(string domainName, QuestionType questionType, CancellationToken cancellationToken)
Parameters
domainNamestringThe domain name to resolve.
questionTypeQuestionTypeThe type of DNS query (e.g., A, AAAA, MX).
cancellationTokenCancellationTokenCancels the query.
Returns
Remarks
Saves passing IN just to reach the token, which is the class almost every caller wants.
Exceptions
- InvalidOperationException
The resolver has no DNS servers configured.
- OperationCanceledException
cancellationTokenwas cancelled.
QueryAsync(string, QuestionType, QuestionClass, CancellationToken)
Sends a DNS query asynchronously.
public Task<Response> QueryAsync(string domainName, QuestionType questionType, QuestionClass questionClass = QuestionClass.IN, CancellationToken cancellationToken = default)
Parameters
domainNamestringThe domain name to resolve.
questionTypeQuestionTypeThe type of DNS query (e.g., A, AAAA, MX).
questionClassQuestionClassThe class of DNS query (e.g., IN for Internet).
cancellationTokenCancellationTokenCancels the query.
Returns
Remarks
A cached answer is returned without awaiting anything. Cancellation is distinct from the configured timeout: a timeout fails over to the next server, cancellation abandons the query.
Exceptions
- InvalidOperationException
The resolver has no DNS servers configured.
- OperationCanceledException
cancellationTokenwas cancelled.