# 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](https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto) from github https://github.com/dnstap/dnstap.pb
## Installation
This module can be installed from [pypi](https://pypi.org/project/dnstap_pb) website
```python
pip install dnstap_pb
```
## Decoder
Example to use the Dnstap decoder
```python
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
```python
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/dmachard/python-dnstap-protobuf",
"name": "dnstap-pb",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "dnstap protobuf decoder encoder",
"author": "Denis MACHARD",
"author_email": "d.machard@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/67/d6/4657379b4300238561729c3ef00902b1c095d5d5bce009356d18a4bb191b/dnstap_pb-0.11.2.tar.gz",
"platform": "any",
"description": "# Dnstap Protocol Buffers implementation in Python\n\nDnstap Protocol Buffers implementation in Python, more informations on dnstap http://dnstap.info/.\nThis library is based on the following [protocol buffers schema](https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto) from github https://github.com/dnstap/dnstap.pb\n\n## Installation\n\nThis module can be installed from [pypi](https://pypi.org/project/dnstap_pb) website\n\n```python\npip install dnstap_pb\n```\n\n## Decoder\n\nExample to use the Dnstap decoder\n\n```python\nimport dnstap_pb\n\n# dnstap decoder\ndnstap = dnstap_pb.Dnstap()\n\npayload = b'\\n\\x08dnsdist1\\x12\\rdnsdist 1.5.0r[\\x08\\x05\\x10\\x01\\x18\\x01\"\\x04\\n\\x00'\npayload += b'\\x00\\xd2*\\x04\\n\\x00\\x00\\xd20\\xe6\\xae\\x0385@\\x8e\\x8f\\xc6\\xff\\x05M\\x1cf,'\npayload += b'\\x15R6\\xda\\xba\\x01 \\x00\\x01\\x00\\x00\\x00\\x00\\x00\\x01\\x03www\\x06google\\x02'\npayload += b'fr\\x00\\x00\\x01\\x00\\x01\\x00\\x00)\\x10\\x00\\x00\\x00\\x00\\x00\\x00\\x0c\\x00\\n\\x00'\npayload += b'\\x08\\xe68\\xe3\\x8e\\x7f\\x01\\xdexx\\x01'\n\ndnstap.ParseFromString(payload)\n\ndm = dnstap.message\nprint(dm)\ntype: CLIENT_QUERY\nsocket_family: INET\nsocket_protocol: UDP\nquery_address: \"\\n\\000\\000\\322\"\nresponse_address: \"\\n\\000\\000\\322\"\nquery_port: 60218\nresponse_port: 53\nquery_time_sec: 1609664434\nquery_time_nsec: 533617553\nquery_message: \"\\221W\\001 \\000\\001\\000\\000\\000\\000\\000\\001\\003www\\006google\\002fr\\000\\000\\001\n\\000\\001\\000\\000)\\020\\000\\000\\000\\000\\000\\000\\014\\000\\n\\000\\010\\273\\257\\370\\014_\\001\\341-\"\n```\n\n## Encoder\n\nExample to use the Dnstap encoder\n\n```python\nimport dnstap_pb\n\n# dnstap encoder\ndnstap = dnstap_pb.Dnstap()\n\n# clear all fields\ndnstap.Clear()\n\n# constructs the message\ndnstap.type = 1\ndnstap.version = b\"0.1.0\"\ndnstap.identity = b\"dnstap_python\"\n\ndnstap.message.type = dnstap_pb.dnstap_pb2._MESSAGE_TYPE.values_by_name[\"CLIENT_QUERY\"].number\ndnstap.message.socket_protocol = dnstap_pb.dnstap_pb2._SOCKETPROTOCOL.values_by_name[\"UDP\"].number\ndnstap.message.socket_family = dnstap_pb.dnstap_pb2._SOCKETFAMILY.values_by_name[\"INET\"].number\n\n# serialize the dnstap message to binary\npayload = dnstap.SerializeToString()\n```\n\n# Development\n\ndnstap_pb2 file generation guideline\n \nDownload dnstap.proto from https://github.com/dnstap/dnstap.pb\n\n```\nwget https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto\n```\n\nDownload protoc\n\n```\nexport VER=21.5\nwget https://github.com/protocolbuffers/protobuf/releases/download/v$VER/protoc-$VER-linux-x86_64.zip\nunzip protoc-$VER-linux-x86_64.zip\n```\n\nGenerate proto\n\n```\npython3 -m pip install protobuf\nbin/protoc --python_out=. dnstap.proto\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Dnstap Protocol Buffers implementation in Python",
"version": "0.11.2",
"project_urls": {
"Homepage": "https://github.com/dmachard/python-dnstap-protobuf"
},
"split_keywords": [
"dnstap",
"protobuf",
"decoder",
"encoder"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ce034721f303f3ed7cfcd6c170931b23f497275ee1bc202dbbfec7b8682748a1",
"md5": "6f1b14941bae06a68df9af68b6c8c6c8",
"sha256": "c9e2036707372e3ccddaf19120d49421a7d418f226ed5ecae4f829038c2a4a02"
},
"downloads": -1,
"filename": "dnstap_pb-0.11.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f1b14941bae06a68df9af68b6c8c6c8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4738,
"upload_time": "2024-09-14T06:42:05",
"upload_time_iso_8601": "2024-09-14T06:42:05.802119Z",
"url": "https://files.pythonhosted.org/packages/ce/03/4721f303f3ed7cfcd6c170931b23f497275ee1bc202dbbfec7b8682748a1/dnstap_pb-0.11.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "67d64657379b4300238561729c3ef00902b1c095d5d5bce009356d18a4bb191b",
"md5": "d0de96b7294ba919edb6cae5ed987d1b",
"sha256": "97ccc0f592a94406395e66ab0779fc24a63867b06b7402b51a434136c31e8370"
},
"downloads": -1,
"filename": "dnstap_pb-0.11.2.tar.gz",
"has_sig": false,
"md5_digest": "d0de96b7294ba919edb6cae5ed987d1b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4590,
"upload_time": "2024-09-14T06:42:06",
"upload_time_iso_8601": "2024-09-14T06:42:06.735010Z",
"url": "https://files.pythonhosted.org/packages/67/d6/4657379b4300238561729c3ef00902b1c095d5d5bce009356d18a4bb191b/dnstap_pb-0.11.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-14 06:42:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dmachard",
"github_project": "python-dnstap-protobuf",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "dnstap-pb"
}