NB: The packet module documentation is not yet complete. At the moment the authoritative docmentation is the source. You might also want to look at the unit tests, and the example programs included with PyOpenBSD.
The packet module is a pure-Python library for creating, inspecting and modifying network packets. Since a complete set of documentation for packet would duplicate much of "TCP/IP Illustrated", this manual will only discuss useful top-level functions and modules, and give a general introduction to working with actual protocol classes. We suggest that documentation for the individual protocol classes be accessed using the "pydoc" tool distributed with Python (e.g. try "pydoc openbsd.packet.TCP").
To ease the common task of interpreting packet data obtained via pcap, the pcap module can automatically instantiate the appropriate packet module protocol classes when packet data is passed back to the user (see the pcap documentation for more information). Most examples in the packet module documentation use the pcap module to read packet information.
The packet module currently supports the following protocols:
The example below does the following:
#!/usr/bin/env python import openbsd o = openbsd.pcap.Offline("foo") o.filter("ip") packet = o.next(interpret=1)[0] print packet packet["ip"].src = "192.168.100.1" packet.finalise() print packet
<--previous | contents | next--> | (12/21/04) |