finds.dev← search

// the find

jvns/teeceepee

★ 566 · Python · updated Nov 2016

mini-TCP stack in Python, for fun

A toy TCP stack written in Python on top of scapy, built purely to understand how TCP works under the hood. It can do enough of the handshake and ACK/reassembly dance to fetch a webpage like curl, but that's about it. For people who want to see TCP state handling as plain Python rather than C, not for anyone who needs an actual network library.

Offloads packet parsing/construction to scapy so the code itself just has to deal with TCP state logic, which keeps it readable. Test suite replays real captured pcap files (google-wget, localhost-wget, a 36000-packet session) instead of just mocking sockets, so the sequence/ack handling is tested against actual traffic. The README is unusually honest about scope and failure modes instead of overselling what it does.

Python 2.7 and last pushed in 2016 — won't run as-is on anything current without a port. Receive-only: no retransmission, no congestion control, can't send data, and handles exactly one connection at a time by the author's own admission. Needs root and ARP-spoofs the gateway to get packets past the kernel's own TCP stack, which the author describes as flaky ('if I run it 5 times it will work') — not something you'd want depending on for anything real. Linux-only; author explicitly expects it to break on BSD and definitely on Windows.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →