tdns¶
An asynchronous Tornado pycares DNS client wrapper, exporting the full API.
Installation¶
tdns is available from the Python Package Index and can be installed by running pip install tdns
Contents¶
tdns API¶
The Channel
implements a Python class for interacting
with the c-ares API using native
Tornado asynchronous conventions. For example,
to query the MX records for google you could use the following snippet:
from tornado import gen, ioloop, web
import tdns
class RequestHandler(web.RequestHandler):
@gen.coroutine
def get(self, *args, **kwargs):
channel = tdns.Channel(io_loop=ioloop.IOLoop.current())
response = yield channel.query('google.com', 'MX')
tnds is build on top of the excellent pycares library.
Ares Channel¶
-
class
tdns.
Channel
(io_loop=None, **kwargs)[source]¶ An asynchronous wrapper class for c-ares channels.
-
cancel
()[source]¶ Cancel any pending query on this channel. All pending requests will raise a
AresError
with theARES_ECANCELLED
errorno.Raises: AresError
-
destroy
()[source]¶ Destroy the channel. All pending requests will raise a
AresError
with theARES_EDESTRUCTION
errorno.Raises: AresError
-
gethostbyaddr
(addr)[source]¶ Retrieves the host information corresponding to a network address.
Parameters: addr (str) – Network address to query Return type: str Raises: AresError
-
gethostbyname
(name, family)[source]¶ Retrieves host information corresponding to a host name from a host database.
Parameters: Raises: AresError
-
getnameinfo
(name, port, flags)[source]¶ Provides protocol-independent name resolution from an address to a host name and from a port number to the service name.
Parameters: Raises: AresError
-
query
(name, query_type)[source]¶ Do a DNS query of the specified type. Available types:
tdns.QUERY_TYPE_A
tdns.QUERY_TYPE_AAAA
tdns.QUERY_TYPE_CNAME
tdns.QUERY_TYPE_MX
tdns.QUERY_TYPE_NAPTR
tdns.QUERY_TYPE_NS
tdns.QUERY_TYPE_PTR
tdns.QUERY_TYPE_SOA
tdns.QUERY_TYPE_SRV
tdns.QUERY_TYPE_TXT
Parameters: Return Types:
- A and AAAA:
ares_query_simple_result
, fields:- host
- ttl
- CNAME:
ares_query_cname_result
, fields:- cname
- ttl
- MX:
ares_query_mx_result
, fields:- host
- priority
- ttl
- NAPTR:
ares_query_naptr_result
, fields:- order
- preference
- flags
- service
- regex
- replacement
- ttl
- NS:
ares_query_ns_result
, fields:
- host
- ttl
- PTR:
ares_query_ptr_result
, fields:- name
- ttl
- SOA:
ares_query_soa_result
, fields:- nsmane
- hostmaster
- serial
- refresh
- retry
- expires
- minttl
- ttl
- SRV:
ares_query_srv_result
, fields:- host
- port
- priority
- weight
- ttl
- TXT:
ares_query_txt_result
, fields:- text
- ttl
Raises: AresError
-
set_local_dev
(local_dev)[source]¶ Set the local ethernet device from which the queries will be sent.
Parameters: local_dev (str) – Network device name Raises: AresError
Raises: ValueError
-
set_local_ip
(local_ip)[source]¶ Set the local IPv4 or IPv6 address from which the queries will be sent.
Parameters: local_ip (str) – IP address Raises: AresError
Raises: ValueError
-
timeout
(max_timeout)[source]¶ Set the maximum time for which the caller should wait before invoking process_fd to process timeouts. If the
max_timeout
parameter is specified, it is stored on the channel and the appropriate value is then returned.Parameters: max_timeout (float) – Maximum timeout Return type: float Raises: AresError
Raises: ValueError
-
Version History¶
- 0.2.0 - released 2016-06-06
- exported constants from pycares.errno
- 0.1.0 - released 2016-04-27
- initial version
Issues¶
Please report any issues to the Github repo at https://github.com/gmr/tdns/issues
Source¶
tdns source is available on Github at https://github.com/gmr/tdns