gevent.dns – Libevent DNS API made synchronous

The functions in this module match those in libevent as closely as possible yet they return the result instead of passing it to a callback. The calling greenlet remains blocked until the result is ready.

exception gevent.dns.DNSError(*args)

A subclass of socket.gaierror used by evdns functions to report errors.

It uses evdns-specific error codes that are different from the standard socket errors.

>>> resolve_ipv4('aaaaaaaaaaa')
Traceback (most recent call last):
 ...
DNSError: [Errno 3] name does not exist
gevent.dns.resolve_ipv4(name, flags=0)

Lookup an A record for a given name. To disable searching for this query, set flags to QUERY_NO_SEARCH.

Returns (ttl, list of packed IPs).

>>> resolve_ipv4('www.python.org')
(10000, ['R^\xa4\xa2'])
gevent.dns.resolve_ipv6(name, flags=0)

Lookup an AAAA record for a given name. To disable searching for this query, set flags to QUERY_NO_SEARCH.

Returns (ttl, list of packed IPs).

gevent.dns.resolve_reverse(packed_ip, flags=0)

Lookup a PTR record for a given IP address. To disable searching for this query, set flags to QUERY_NO_SEARCH.

>>> packed_ip = socket.inet_aton('82.94.164.162')
>>> resolve_reverse(packed_ip)
(10000, 'www.python.org')
gevent.dns.resolve_reverse_ipv6(packed_ip, flags=0)

Lookup a PTR record for a given IPv6 address. To disable searching for this query, set flags to QUERY_NO_SEARCH.

Next page: gevent.select