Skip to main content

Dnstap Protocol Buffers implementation in Python

Project description

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

wget https://github.com/protocolbuffers/protobuf/releases/download/v3.18.0/protoc-3.18.0-linux-x86_64.zip
unzip protoc-3.18.0-linux-x86_64.zip

Generate proto

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

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

dnstap_pb-0.4.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

dnstap_pb-0.4.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file dnstap_pb-0.4.0.tar.gz.

File metadata

  • Download URL: dnstap_pb-0.4.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for dnstap_pb-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d24c8e6bcd611a981ce958fea5478a1b6a9d9b1c83f5ffb10b360ba49f27d342
MD5 4a13ebb35d0359e453a59055dd6f38f6
BLAKE2b-256 fc33c632e5f04a455173814d61c704f0fbcd1466a239873a28ddde82fdfb70ec

See more details on using hashes here.

File details

Details for the file dnstap_pb-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: dnstap_pb-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for dnstap_pb-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9cb7561d50c567477052da7d485544829dd31ade14d15885ec277d305f34435
MD5 6ab3b70b4f2e6f15fc8f69e0dc98fa21
BLAKE2b-256 d700ee918f9b7523a4081734082a7fe33899b354529139d51ba3b524b76b310a

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