Asynchronous DNS resultion in Python by using adns C library.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a tiny Python library for resolving a lot of DNS records
asynchronously. On a speedy internet connection it managed to do
20,000 resolutions per minute.

It was written by Peteris Krumins (
His blog is at  --  good coders code, great reuse.

The code is licensed under the MIT license.

The code was written as a part of the article "Resolving DNS Asynchronously"
on my website. The whole article can be read at:


Table of contents:
    [1] The problem.
    [2] The solution and how to use
    [3] What is included in this source tree?


Once upon a time, I had to quickly resolve thousands of DNS names. My first
solution was to call gethostbyname repeatedly for each of the hosts. This
turned out to be extremely slow. I could only do 200 hosts in a minute. I
talked with someone and he suggested to try to do it asynchronously. I looked
around and found adns - asynchronous dns library written in C (see link (1)
below). Since I was writing the code in Python, I looked around some more and
found Python bindings for adns (see link (2) below). I tried adns and - wow -
I could do 20,000 hosts in a minute!


Continue reading on

Link references:



I wrote Python module to do the resolution. It uses Python
wrapper for adns C library (see links (1) and (2) above).

The module exports AsyncResolver class. The constructor of this
class takes a list of domains to resolve.

Here is an example that resolves three domains asynchronously:

    from async_dns import AsyncResolver

    ar = AsyncResolver(
           ["", "", ""]
    resolved = ar.resolve()

    for host, ip in resolved.items():
      if ip is None:
        print "%s could not be resolved." % host
        print "%s resolved to %s" % (host, ip)

The constructor of Asynchronously also takes 'intensity' paramter, which
specifies how many hosts to resolve asynchronously at once.

Calling the resolve() member function on an AsyncResolver object starts
resolving all the domains that were passed to AsyncResolver constructor.

Once it's done, it returns a dictionary of { 'host': 'ip' } structure.


The file is my first attempt at resolving a lot of DNS hosts. It
uses the standard system resolver "gethostbyname" from Python's socket module.

It can only do 200 resolutions per minute.

Python module exports resolve_slow function, it takes a list of
hosts as an argument, resolves them, and returns a dictionary of
{ 'host': 'ip' } pairs.

You can use it the following way:

    from slow_dns import resolve_slow

    resolved = resolve_slow(['', ''])
    for host, ip in resolved.items():
      if ip is None:
        print "%s could not be resolved." % host
        print "%s resolved to %s" % (host, ip)


See my original article for more information on both and

It's here:


That's it. Happy asynchronous resolution!

Peteris Krumins