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
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.
Install PublicDNS using easy_setup or pip:
pip install publicdns
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.
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 ofpublicdns.models.DNSResponse.resolve(host, type='A', dnssec=True): Do a DNS resolution of the given type for the given hostname. Whilequery()returns an instance ofpublicdns.models.DNSResponse,resolve()only return a list of data like['8.8.8.8'].
Replace some functions of the standard socket object with publicdns's implementation.
from publicdns.monkey import patch_socket patch_socket()
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.
Google can limit the number of API requests. Please follow Rate-limiting queries section.
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
- Create an issue and describe your idea
- Fork this repo
- Create your feature branch (
git checkout -b my-new-feature) - Run tests
- Add a test for your feature
- Run step 4 again
- Commit your changes (
git commit -am 'Add some feature') - Publish the branch (
git push origin my-new-feature) - Create a new Pull Request
PublicDNS is released under the MIT License.