Class LookupClient
The LookupClient is the main query class of this library and should be used for any kind of DNS lookup query.
It implements ILookupClient and IDnsQuery which contains a number of extension methods, too.
The extension methods internally all invoke the standard IDnsQuery queries though.
Namespace:DnsClient
Assembly:DnsClient.dll
Syntax
public class LookupClient : ILookupClient, IDnsQuery
Examples
A basic example wihtout specifying any DNS server, which will use the DNS server configured by your local network.
var client = new LookupClient();
var result = client.Query("google.com", QueryType.A);
foreach (var aRecord in result.Answers.ARecords())
{
Console.WriteLine(aRecord);
}
Constructors
|
Improve this Doc
View Source
LookupClient()
Creates a new instance of LookupClient without specifying any name server.
This will implicitly use the name server(s) configured by the local network adapter.
Declaration
Examples
In the following example, we will create a new LookupClient without explicitly defining any DNS server.
This will use the DNS server configured by your local network.
var client = new LookupClient();
var result = client.Query("google.com", QueryType.A);
foreach (var aRecord in result.Answers.ARecords())
{
Console.WriteLine(aRecord);
}
|
Improve this Doc
View Source
LookupClient(IPAddress, Int32)
Create a new instance of LookupClient with one DNS server defined by address and port.
Declaration
public LookupClient(IPAddress address, int port)
Parameters
Examples
In case you want to connect to one specific DNS server which does not run on the default port 53
, you can do so like in the following example:
var client = new LookupClient(IPAddress.Parse("127.0.0.1"), 8600);
|
Improve this Doc
View Source
LookupClient(IPAddress[])
Creates a new instance of LookupClient with one or more DNS servers identified by their IPAddress.
The default port 53
will be used for all IPAddresss provided.
Declaration
public LookupClient(params IPAddress[] nameServers)
Parameters
Examples
To connect to one or more DNS server using the default port, we can use this overload:
// configuring the client to use google's public IPv4 DNS servers.
var client = new LookupClient(IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4"));
|
Improve this Doc
View Source
LookupClient(IPEndPoint[])
Declaration
public LookupClient(params IPEndPoint[] nameServers)
Parameters
Examples
In this example, we instantiate a new IPEndPoint using an IPAddress and custom port which is different than the default port 53
.
// Using localhost and port 8600 to connect to a Consul agent.
var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8600);
var client = new LookupClient(endpoint);
The NameServer class also contains pre defined IPEndPoints for the public google DNS servers, which can be used as follows:
var client = new LookupClient(NameServer.GooglePublicDns, NameServer.GooglePublicDnsIPv6);
Properties
|
Improve this Doc
View Source
EnableAuditTrail
Declaration
public bool EnableAuditTrail { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
MinimumCacheTimeout
Declaration
public TimeSpan? MinimumCacheTimeout { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
NameServers
Declaration
public IReadOnlyCollection<NameServer> NameServers { get; }
Property Value
Implements
|
Improve this Doc
View Source
Recursion
Declaration
public bool Recursion { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
Retries
Declaration
public int Retries { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
ThrowDnsErrors
Declaration
public bool ThrowDnsErrors { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
Timeout
Declaration
public TimeSpan Timeout { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
UseCache
Declaration
public bool UseCache { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
UseTcpFallback
Declaration
public bool UseTcpFallback { get; set; }
Property Value
Implements
|
Improve this Doc
View Source
UseTcpOnly
Declaration
public bool UseTcpOnly { get; set; }
Property Value
Implements
Methods
|
Improve this Doc
View Source
Query(String, QueryType)
Declaration
public IDnsQueryResponse Query(string query, QueryType queryType)
Parameters
Returns
Implements
|
Improve this Doc
View Source
Query(String, QueryType, QueryClass)
Declaration
public IDnsQueryResponse Query(string query, QueryType queryType, QueryClass queryClass)
Parameters
Returns
Implements
|
Improve this Doc
View Source
QueryAsync(String, QueryType)
Declaration
public Task<IDnsQueryResponse> QueryAsync(string query, QueryType queryType)
Parameters
Returns
Implements
|
Improve this Doc
View Source
QueryAsync(String, QueryType, QueryClass)
Declaration
public Task<IDnsQueryResponse> QueryAsync(string query, QueryType queryType, QueryClass queryClass)
Parameters
Returns
Implements
|
Improve this Doc
View Source
QueryAsync(String, QueryType, QueryClass, CancellationToken)
Declaration
public Task<IDnsQueryResponse> QueryAsync(string query, QueryType queryType, QueryClass queryClass, CancellationToken cancellationToken)
Parameters
Returns
Implements
|
Improve this Doc
View Source
QueryAsync(String, QueryType, CancellationToken)
Declaration
public Task<IDnsQueryResponse> QueryAsync(string query, QueryType queryType, CancellationToken cancellationToken)
Parameters
Returns
Implements
|
Improve this Doc
View Source
QueryReverse(IPAddress)
Declaration
public IDnsQueryResponse QueryReverse(IPAddress ipAddress)
Parameters
Returns
Implements
|
Improve this Doc
View Source
QueryReverseAsync(IPAddress)
Declaration
public Task<IDnsQueryResponse> QueryReverseAsync(IPAddress ipAddress)
Parameters
Returns
Implements
|
Improve this Doc
View Source
QueryReverseAsync(IPAddress, CancellationToken)
Declaration
public Task<IDnsQueryResponse> QueryReverseAsync(IPAddress ipAddress, CancellationToken cancellationToken)
Parameters
Returns
Implements
Extension Methods
See Also