Community Python Snippet

The tcpdump One-Liner I Actually Remember

A small Python wrapper around the only tcpdump invocation I can recall under pressure, plus a parser that turns its line-buffered output into JSON so I can pipe it to jq.

The tcpdump One-Liner I Actually Remember

A small Python wrapper around the only tcpdump invocation I can recall under pressure, plus a parser that turns its line-buffered output into JSON so I can pipe it to jq.

Python
Compiler
3 snippets
debugging
networking
code-template
utility
elisehuang

By @elisehuang

March 17, 2026

·

Updated May 18, 2026

382 views

3

4.4 (9)

Every time my service stops talking to a downstream and metrics are unhelpful, I reach for tcpdump. The flags I always need are -A (ASCII payload so HTTP headers are readable), -s 0 (full snaplen, otherwise headers cut at 96 bytes), -l (line-buffered so piping to grep actually flushes), and -nn (skip DNS, which can take seconds on a slow resolver). The function exists so I stop typing -s 96 and wondering why my Authorization header is truncated. On macOS BSD tcpdump, replace -i any with an explicit interface like -i en0.