Asyncio Python DNS resolver
Project description
aiodnsresolver
Asyncio Python DNS resolver. Pure Python, with no dependencies other than the standard library, threads are not used, and all code is in a single module. The nameservers to query are taken from /etc/resolve.conf
.
Based on https://github.com/gera2ld/async_dns.
Installation
pip install aiodnsresolver
Usage
from aiodnsresolver import Resolver, TYPES
resolve = Resolver()
ip_address = await resolve('www.google.com', TYPES.A)
The IP address returned is an instance of IPv4Address or IPv6Address. Both support conversion to their usual string form by passing them to str
.
Security considerations
To migitate spoofing, several techniques are used.
-
Each query is given a random ID, which is checked against any response.
-
Each domain name is encoded with 0x20-bit encoding, which is checked against any response.
-
A new socket, and so a new random local port, is used for each query.
Scope
The scope of this project is deliberately restricted to operations that are used to resolve A or AAAA records: to resolve a domain name to one of its IP addresses, and have similar responsibilities to gethostbyname
. Some limited extra behaviour is present/may be added, but great care is taken to prevent scope creep, especially to not add complexity that isn't required to resolve A or AAAA records.
-
UDP queries are made, but not TCP. DNS servers must support UDP, and it's impossible for a single A and AAAA record to not fit into the maximum size of a UDP DNS response, 512 bytes. There may be other data that the DNS server would return in TCP connections, but this isn't required to resolve a domain name to a single IP address.
-
CNAME records are followed transparently.
-
Responses are cached, adhering to their TTL.
-
The resolver is a stub resolver: it delegates the responsibility of recursion to the nameserver(s) it queries. In the vast majority of envisioned use cases this is acceptable, since the nameservers in
/etc/resolve.conf
will be recursive.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aiodnsresolver-0.0.38-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd33eef62d2e79e8b3774d292352ea32804c84b9666e1608caf010b3a2045f4 |
|
MD5 | 6b7fc7c3ff7e8a13e81528544c4bcb07 |
|
BLAKE2b-256 | b6d3e755373c922dea9d05cbfcb43ade05ba8ff428dceab54decac300056b5f2 |