Skip to main content

No project description provided

Project description

Python DNS Client Library

PyPI - Python Version PyPI - Python Version PyPI - Downloads

Python client library for sending DNS queries.

Featurtes:

  • supports DNS over TLS (DOT)
  • contains adapter for requests
  • threadsafe
  • null-dependency

Install:

# from pypi.org
pip install dns-client

# latest commit
pip install git+https://github.com/s3rgeym/python-dns-client.git

Examples:

In [1]: from dns_client import DNSClient, RecordType

In [2]: c = DNSClient('1.1.1.1', over_tls=True)

In [3]: c.query('ya.ru', RecordType.AAAA)
Out[3]: [Record(name='ya.ru', qtype=<RecordType.AAAA: 28>, qclass=<RecordClass.IN: 1>, ttl=76, value='2a02:6b8::2:242')]

In [4]: c.query('ya.ru', RecordType.MX)
Out[4]: [Record(name='ya.ru', qtype=<RecordType.MX: 15>, qclass=<RecordClass.IN: 1>, ttl=2242, value=(10, 'mx.yandex.ru'))]

In [5]: c.get_query_response('ya.ru')
Out[5]: Packet(header=Header(id=47527, response=True, opcode=<OpCode.QUERY: 0>, authoritative=False, truncated=False, recursion_desired=True, recursion_available=True, reserved=False, authentic_data=False, check_disabled=False, rcode=<ResponseCode.NOERROR: 0>, num_questions=1, num_records=2, num_authorities=0, num_additionals=0), questions=[Question(name='ya.ru', qtype=<RecordType.A: 1>, qclass=<RecordClass.IN: 1>)], records=[Record(name='ya.ru', qtype=<RecordType.A: 1>, qclass=<RecordClass.IN: 1>, ttl=266, value='77.88.55.242'), Record(name='ya.ru', qtype=<RecordType.A: 1>, qclass=<RecordClass.IN: 1>, ttl=266, value='5.255.255.242')])

In [6]: c.get_all_records('ya.ru')
Out[6]:
[('A', '5.255.255.242'),
 ('A', '77.88.55.242'),
 ('AAAA', '2a02:6b8::2:242'),
 ('MX', (10, 'mx.yandex.ru')),
 ('NS', 'ns1.yandex.ru'),
 ('NS', 'ns2.yandex.ru'),
 ('TXT',
  '_globalsign-domain-verification=eLi0_-xATuNmRfuTIX8VQIvgfyi7Od7Hph4V0yNisF'),
 ('TXT',
  '_globalsign-domain-verification=xUUDG4u7Zo56EmmFewz7Y4UK3MfAU7QSjAgBsy0w6q'),
 ('TXT',
  'google-site-verification=SVTEeUiCU4KV-5qGw4o4JPok7mfsP8NtQTIdN6tt6Nw'),
 ('TXT', 'v=spf1 redirect=_spf.yandex.ru'),
 ('TXT',
  '_globalsign-domain-verification=dHoe580bPQ-lfi_vh-BEIwB4NAtUwURIzrzsivByVL'),
 ('TXT', 'e1c8e4dd3d13fad0dd9e8ed54a1813ececd3d5412fb16c4ed2c0612332950fe')]

You can use dns-client with requests:

from dns_client.adapters.requests import DNSClientSession

s = DNSClientSession('1.1.1.1')
r = s.get('https://google.com')
print(r.headers)

CLI Usage:

$ python -m dns_client ya.ru -t ns -H 8.8.8.8 --tls -pr
Response Flags = 0x8180

1... .... .... .... = Response (True)
.000 0... .... .... = Opcode (<OpCode.QUERY: 0>)
.... .0.. .... .... = Authoritative (False)
.... ..0. .... .... = Truncated (False)
.... ...1 .... .... = Recursion Desired (True)
.... .... 1... .... = Recursion Available (True)
.... .... .0.. .... = Reserved (False)
.... .... ..0. .... = Authentic Data (False)
.... .... ...0 .... = Check Disabled (False)
.... .... .... 0000 = Rcode (<ResponseCode.NOERROR: 0>)

Number of Records       : 2
Number of Questions     : 1
Number of Authorities   : 0
Number of Additionals   : 0

ns1.yandex.ru
ns2.yandex.ru
Arg Desc
-t record type
-H dns address
--tls dns over tls aka d.o.t.
-pr print response

See all arguments:

python -m dns_client -h

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

dns-client-0.2.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

dns_client-0.2.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file dns-client-0.2.1.tar.gz.

File metadata

  • Download URL: dns-client-0.2.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for dns-client-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f12ac7eedbe569bb229a8e4a7448f4de41862a16b591c451cfefe7b4bebee929
MD5 d7fd43b7eff1726200daca98a411e166
BLAKE2b-256 e15a62cad6755665d4b4ba8c7523cebace76df2913a0ec076bf0bfda6dee1601

See more details on using hashes here.

File details

Details for the file dns_client-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dns_client-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for dns_client-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 755c051410e21e1e25dc767a6e1e0488cc4443ba6e659ac387cff799364511d2
MD5 d81f0c7fbc5d7f2a4d677360d183a149
BLAKE2b-256 ab2c249077aa965e03db7c4a6425193b50b37284e68324d3f6d1bd6a0ae47c05

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