Simple Python DNS Library. DNS Packet-Parsing/Client/Server
Project description
pydns
Simple Python DNS Library. DNS Packet-Parsing/Client/Server
Installation
pip install pydns3
Examples
Packet Parsing
from pydns import Message
raw = \
b"\x5c\x7d\x81\x80\x00\x01\x00\x00\x00\x01\x00\x01\x03\x77\x77\x77" \
b"\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00\x00\x06\x00\x01" \
b"\xc0\x10\x00\x06\x00\x01\x00\x00\x00\x3c\x00\x26\x03\x6e\x73\x31" \
b"\xc0\x10\x09\x64\x6e\x73\x2d\x61\x64\x6d\x69\x6e\xc0\x10\x1e\xe8" \
b"\x04\x72\x00\x00\x03\x84\x00\x00\x03\x84\x00\x00\x07\x08\x00\x00" \
b"\x00\x3c\x00\x00\x29\x04\xd0\x00\x00\x00\x00\x00\x00"
req = Message.unpack(raw)
print(req)
Client
from pydns import Question, RType
from pydns.client import UdpClient
client = UdpClient([('8.8.8.8', 53)])
query = Question(b'www.google.com', RType.AAAA)
res = client.query(query)
print(res)
Simple Server
import logging
from pyserve import listen_udp_threaded
from pydns.client import UdpClient
from pydns.server import Server
from pydns.server.backend import MemoryBackend, Forwarder, Cache
# declare and configure server address and forwarding client addresses
server_addr = ('127.0.0.1', 53)
client_addrs = [('8.8.8.8', 53)]
# prepare simple memory backend as base provider
backend = MemoryBackend()
backend.save_domain_dict(b'example.com', {
'A': [{'ip': '1.2.3.4'}],
'MX': [{'preference': 1, 'exchange': b'mx.example.com'}],
'SOA': [{
'mname': b'mname.example.com',
'rname': b'rname.example.com',
'serialver': 1,
'refresh': 2,
'retry': 3,
'expire': 4,
'minimum': 5
}]
})
# wrap memory backend w/ client forwarder
client = UdpClient(client_addrs)
backend = Forwarder(backend, client)
# wrap backend w/ cache to cache forwarded content
backend = Cache(backend)
# configure optional logger for server implementaion
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('myserver')
logger.setLevel(logging.INFO)
# launch server and run forever using pyserve
listen_udp_threaded(server_addr, Server, backend=backend, logger=logger)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydns3-0.0.10.tar.gz
(23.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pydns3-0.0.10-py3-none-any.whl
(30.5 kB
view details)
File details
Details for the file pydns3-0.0.10.tar.gz.
File metadata
- Download URL: pydns3-0.0.10.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c33402db6e0e6ad2076790c1aa621eb3e9dca807c6e96d7f52d5de03f2dda5a2
|
|
| MD5 |
d5fdd2f22594bfdbfe2bf08fc891c31a
|
|
| BLAKE2b-256 |
842609ab28c9deb27a58f95d652bf813b29a1ff0d5da7974050a002b74e4690a
|
File details
Details for the file pydns3-0.0.10-py3-none-any.whl.
File metadata
- Download URL: pydns3-0.0.10-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63b811a301edc8f1d3ac0db95bd4140c469418e1dfd8945653c1322e8e74debf
|
|
| MD5 |
a822f30696ceccf36e4c9f6e59d719aa
|
|
| BLAKE2b-256 |
70d71e190bcbbfd14fe3774b184c72eaabcb6c9a2a6ae9ec94dc301b141d2acb
|