Skip to content
This repository was archived by the owner on Jun 21, 2021. It is now read-only.

Repository files navigation

PublicDNS

Code Climate https://travis-ci.org/ssut/public-dns.svg?branch=master https://coveralls.io/repos/github/ssut/public-dns/badge.svg?branch=master

PublicDNS is a high-perfmrnace, secure, reliable python DNS client over HTTP/2 and TLS.

As written in Google DNS-over-HTTPS guide, this offers a variety of features as follows:

  • support all RRs
  • support DNSSEC validation
  • support for IPv4 and IPv6
  • support edns-client-subnet
  • can insure against privacy concerns
    • ISPs will not able to track which DNS names you have queried

Performance

While tranditional DNS client does not support put multiple questions into a single call, PublicDNS has advantage that it's much faster when dealing with multiple questions, a big advantage of HTTP/2. Because Google servers also run over QUIC, this means that performance will be much better if it is implemented.

I recently benchmarked with a small amount of domains, take a look at the result:

- dns.resolver
100%|███| 100/100 [00:32<00:00, 3.97s/it]
dns.resolver * 100 - took 32.5060371872969s
- PublicDNS
100%|███| 100/100 [00:13<00:00, 12.8it/s]
PublicDNS * 100 - took 13.507565873209387s

Note that results will vary depend on the network since most dns servers use IP Anycast. Further, PublicDNS needs only one TCP connection as did in the benchmark, whereas traditional clients will need to establish multiple TCP or UDP connections.

Installation

Install PublicDNS using easy_setup or pip:

pip install publicdns

Example

from publicdns.client import PublicDNS

client = PublicDNS()
result = client.query('www.google.com', 'A')
ip = client.resolve('www.google.com')

To see more usage, just dive into the tests directory.

API

The public API is really simple, totaling only 2 API calls:

  • query(host, type='A', dnssec=True): Do a DNS resolution of the given type for the given hostname. It returns an instance of publicdns.models.DNSResponse.
  • resolve(host, type='A', dnssec=True): Do a DNS resolution of the given type for the given hostname. While query() returns an instance of publicdns.models.DNSResponse, resolve() only return a list of data like ['8.8.8.8'].

Patching

Replace some functions of the standard socket object with publicdns's implementation.

from publicdns.monkey import patch_socket
patch_socket()

Documentation

Until the project is properly documented you will have to rely on the source code. It is rather undocumented now, but better documentation is under way. On the other hand, the code is quite extensively tested.

Query Limitation

Google can limit the number of API requests. Please follow Rate-limiting queries section.

Running tests

PublicDNS has tests. These tests ensure that the code is in a working state. You have to install some external packages to run tests, listed in test_requirements.txt:

$ pip install -r test_requirements.txt

then:

$ py.test

Alternatively, to run them in every supported Python version do:

$ tox

Contributing

  1. Create an issue and describe your idea
  2. Fork this repo
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Run tests
  5. Add a test for your feature
  6. Run step 4 again
  7. Commit your changes (git commit -am 'Add some feature')
  8. Publish the branch (git push origin my-new-feature)
  9. Create a new Pull Request

License

PublicDNS is released under the MIT License.

About

A quick python implementation for google public dns service, using DNS-over-HTTPS.

Topics

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages