Python Notes

Sunday, January 16, 2005

Low-level networking with Python

If for any reason you ever need to write low-level network protocols, and if you need direct access to the wire, a good starting pointer is on the Vaults of Parnassus Networking section. It contains pointers to some implementations of the libpcap library, the de-facto standard for low level network access. There is also a free port of libpcap for Windows, named WinPcap.

The reason to use libpcap is simple. First, it's a standard interface. Also, because although you can send low level packets (including broadcasts) using standard socket calls, there is no easy way to listen for arbitrary packets. It's actually a security feature, although I have a hard time figuring out the exact details behind this design decision.

I'm now playing with pcapy, a simple Python object-oriented wrapper around libpcap. Besides its simplicity, it's also one of the few libraries that work both on Linux and Windows (using WinPcap if available). There is also a good library named Billy the Kid, or btk, which includes not only libpcap, but also a good packet construction library, that can be used to build arbitrary packets. It's Linux only (it's distributed as a source C extension); at this moment I don't know what would take to compile it for Windows.

30 Comments:

Post a Comment

<< Home