Skip to main content

dnspython compatible DNSCrypt Resolver

Project description

This library is designed to make using DNSCrypt in Python easy and compatible with dnspython. It provides a dns.resolver.Resolver-style interface which mixes-in the dns.query.udp and dns.query.tcp functions.

>>> import dnscrypt
>>> r = dnscrypt.Resolver('208.67.222.222', '2.dnscrypt-cert.opendns.com',
... 'B735:1140:206F:225D:3E2B:D822:D7FD:691E:A1C3:3CC8:D666:8D0C:BE04:BFAB:CA43:FB79',
... port=53, timeout=5)
>>> print r.query('www.google.com')
<dns.resolver.Answer object at 0x103b6f450>
>>> import dns.message
>>> r.udp(dns.message.make_query('google.com', 'A'))
<DNS message, ID 16075>

Class Methods

__init__(self, address, provider_name, provider_pk, private_key=None, port=53, timeout=5)

address

The IP address of the DNSCrypt resolver

port

The port to use for communication with the DNSCrypt resolver

provider_name

The provider name for the DNSCrypt resolver. Takes the format <version>.dnscrypt-cert.<zone>.

provider_pk

The provider’s hex-encoded public key or DNS hostname where to retreive the public key

private_key

A hex-encoded private key if you want to reuse a key you already have. Otherwise, a new key will be generated for each Resolver instance.

timeout

Timeout in seconds for DNS lookups

address, provider_name, and provider_pk are required. All other arguments are optional.

query(qname, rdtype=1, rdclass=1, tcp=False, source=None, raise_on_no_answer=True, source_port=0)

Analogous to dns.resolver.Resolver.query for dnspython.

tcp(self, query, timeout=None, af=None, source=None, source_port=0, one_rr_per_rrset=False)

Analogous to dns.query.tcp for dnspython. There is no where argument, but is otherwise identical in function/form.

udp(self, query, timeout=None, af=None, source=None, source_port=0, ignore_unexpected=False, one_rr_per_rrset=False)

Analogous to dns.query.udp for dnspython. There is no where argument, but is otherwise identical in function/form.

Differences from dnspython

The biggest thing is that this is a very basic implementation of dns.resolver.Resolver. While it’s designed to look/feel the same, it is not a drop in replacement. (e.g. I did not implement the use_tsig/use_edns/set_flags functions, instead use dns.message.Message and dnscrypt.resolver.tcp or dnscrypt.resolver.udp.)

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

dnscrypt-1.0.1.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file dnscrypt-1.0.1.tar.gz.

File metadata

  • Download URL: dnscrypt-1.0.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dnscrypt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8ba0e824bf0515e962ffffcff9650b1d7f739e52114cf62b930e299450023720
MD5 0522bf596b0c6aafbd7c123ebd98fd26
BLAKE2b-256 f1399d9cea927a94410fef1a58e91e02203ab686ffb9e88e270c1d5b7b936c47

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