CalPack: Packets in Python Simplified¶
CalPack is the only package you’ll need to create, generate and parse packets in an easy to use way. This module wraps
the ctypes
module into an easier to use interface and enabling more features specific to working with Packets.
Examples¶
Creating a new packet is as simple as creating a python class:
from calpack import models
class UDP(models.Packet):
source_port = models.IntField()
dest_port = models.IntField()
length = models.IntField()
checksum = models.IntField()
Since calpak
is a wrapper to ctypes
, the above class is equivalent to the following
ctypes.Structure
:
import ctypes
class UDP(ctypes.Structure):
_fields_ = [
('source_port', ctypes.c_uint64, 16),
('dest_port', ctypes.c_uint64, 16),
('length', ctypes.c_uint64, 16),
('checksum', ctypes.c_uint64, 16),
]
Interacting with the packet and it’s field is also simple:
p = UDP()
p.source_port = 80
p.dest_port = 80
p.length = 8