create classes to (un)pack packets to/from objects with named fields
Project description
The packet module is a front-end to the struct module. It allows the user to define a packet format, and to create a Python class to represent those packets with named attributes for each packet field:
# demo: make an IP packet packer/unpacker
# IP Prototype
ipp = Prototype()
ipp.add_uint8('vhl')
ipp.add_uint8('tos')
ipp.add_uint16('len')
ipp.add_uint16('id')
ipp.add_uint16('off')
ipp.add_uint8('ttl')
ipp.add_uint8('p')
ipp.add_uint16('sum')
ipp.add_uint32('src')
ipp.add_uint32('dst')
IP = ipp.klass('IP', NETWORK)
del ipp
# ....
# create an IP packet instance from bytes
packet = IP(bytes)
# create an empty packet
packet = IP()
# access fields
print(packet.len)
# pack fields into bytes
bytes = packet.pack()
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
packet-0.5.tar.gz
(4.0 kB
view details)
File details
Details for the file packet-0.5.tar.gz.
File metadata
- Download URL: packet-0.5.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09a2d8e70b6860548a7c558f7fff7d2ab4b52275a7d0a488b3e93e876740cf6e
|
|
| MD5 |
06498fe882ff62fcc92c86b548e1d975
|
|
| BLAKE2b-256 |
d636b8c30cf6e41c9f9419e13271879b4aa6602799741a3e9de71e6331643cad
|