Skip to main content

Pure Python asynchronous DNS via asyncio

Project description

asyncdns - Pure Python asynchronous DNS for asyncio

https://travis-ci.org/al45tair/asyncdns.svg?branch=master https://readthedocs.org/projects/asyncdns/badge/?version=latest

What is this?

asyncdns is a pure Python asynchronous DNS resolver implementation written on top of asyncio. It doesn’t require any external libraries, and it doesn’t use threads or blocking functions.

Usage

asyncdns doesn’t have an equivalent to the widely used gethostbyname() or getaddrinfo() functions. Instead, you use it by constructing a Query object specifying the DNS query you wish to run, then pass it to a Resolver to actually perform the query.

There are a handful of built-in resolvers, but for demonstration purposes the easiest one to use is the SmartResolver, which automatically makes use of /etc/hosts, multicast DNS and regular DNS as appropriate.

For instance, do a simple lookup for an A record:

>>> import asyncdns, asyncio
>>> resolver = asyncdns.SmartResolver()
>>> loop = asyncio.get_event_loop()
>>> query = asyncdns.Query('www.example.com', asyncdns.A, asyncdns.IN)
>>> f = resolver.lookup(query)
>>> loop.run_until_complete(f)
>>> print(f.result())
;; No error (RD, RA)
; 1 answers:
www.example.com       54950   IN      A       93.184.216.34
; 0 authorities:
; 0 additional:

Note that you may or may not want to use SmartResolver in your code, depending on your requirements - it probably isn’t a good idea using multicast DNS on an untrusted network, for instance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncdns2-0.1.3.tar.gz (19.1 kB view details)

Uploaded Source

File details

Details for the file asyncdns2-0.1.3.tar.gz.

File metadata

  • Download URL: asyncdns2-0.1.3.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for asyncdns2-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8cba069a985f186e00afbd377a8a8e63900922d4d70c2256b6d3a363d278e2ae
MD5 2844e669a316765d5664e9e6def1e7e5
BLAKE2b-256 17b87800831a737c76991eb280251dcf9486652878056a2a43f20ea6c352ffc0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page