Skip to main content

Dnstap Protocol Buffers implementation in Python

Dnstap Protocol Buffers implementation in Python, more informations on dnstap http://dnstap.info/. This library is based on the following protocol buffers schema.

Installation

This module can be installed from pypi website

pip install dnstap_pb

Decoder

Example to use the Dnstap decoder

import dnstap_pb

# dnstap decoder
dnstap = dnstap_pb.Dnstap()

payload = b'\n\x08dnsdist1\x12\rdnsdist 1.5.0r[\x08\x05\x10\x01\x18\x01"\x04\n\x00'
payload += b'\x00\xd2*\x04\n\x00\x00\xd20\xe6\xae\x0385@\x8e\x8f\xc6\xff\x05M\x1cf,'
payload += b'\x15R6\xda\xba\x01 \x00\x01\x00\x00\x00\x00\x00\x01\x03www\x06google\x02'
payload += b'fr\x00\x00\x01\x00\x01\x00\x00)\x10\x00\x00\x00\x00\x00\x00\x0c\x00\n\x00'
payload += b'\x08\xe68\xe3\x8e\x7f\x01\xdexx\x01'

dnstap.ParseFromString(payload)

dm = dnstap.message
print(dm)
type: CLIENT_QUERY
socket_family: INET
socket_protocol: UDP
query_address: "\n\000\000\322"
response_address: "\n\000\000\322"
query_port: 60218
response_port: 53
query_time_sec: 1609664434
query_time_nsec: 533617553
query_message: "\221W\001 \000\001\000\000\000\000\000\001\003www\006google\002fr\000\000\001
\000\001\000\000)\020\000\000\000\000\000\000\014\000\n\000\010\273\257\370\014_\001\341-"

Encoder

Example to use the Dnstap encoder

import dnstap_pb

# dnstap encoder
dnstap = dnstap_pb.Dnstap()

# clear all fields
dnstap.Clear()

# constructs the message
dnstap.type = 1
dnstap.version = b"0.1.0"
dnstap.identity = b"dnstap_python"

dnstap.message.type = dnstap_pb.dnstap_pb2._MESSAGE_TYPE.values_by_name["CLIENT_QUERY"].number
dnstap.message.socket_protocol = dnstap_pb.dnstap_pb2._SOCKETPROTOCOL.values_by_name["UDP"].number
dnstap.message.socket_family = dnstap_pb.dnstap_pb2._SOCKETFAMILY.values_by_name["INET"].number

# serialize the dnstap message to binary
payload = dnstap.SerializeToString()

Development

dnstap_pb2 file generation guideline

Download dnstap.proto from https://github.com/dnstap/dnstap.pb

wget https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto

Download protoc

export VER=21.5
wget https://github.com/protocolbuffers/protobuf/releases/download/v$VER/protoc-$VER-linux-x86_64.zip
unzip protoc-$VER-linux-x86_64.zip

Generate proto

python3 -m pip install protobuf
bin/protoc --python_out=. dnstap.proto

Release files for dnstap-pb 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnstap-pb 0.8.0
File Size Uploaded
dnstap_pb-0.8.0.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dnstap-pb 0.8.0
File Interpreter ABI Platform
dnstap_pb-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / dnstap_pb-0.8.0.tar.gz

Download URL dnstap_pb-0.8.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8e93ce1e05cf22a50faf3921b415a3080af85c5f686092f91c41611655551a90
BLAKE2b-256 checksum
How to use checksums
5e6d86af123d749a528ebc9655806d8a8f7704d7193a96a98fd759f1c4c280e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / dnstap_pb-0.8.0-py3-none-any.whl

Download URL dnstap_pb-0.8.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f34eda370cabd5efbcd442e0879181cc1b8d86aabb6daa2d201fd7c4d92ea61
BLAKE2b-256 checksum
How to use checksums
6d7f5f4c65a2fdfc34c47298da3883c1fcd0475af0c2b266e283a96294b47c4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

0.11.3

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.9.0

2 release files

This release

0.8.0 This release

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page