Small Scapy-based packet sniffer. Captures packets, prints human-readable lines, logs to file and saves captures to a pcap.
- Windows or Unix with Python 3.8+
- scapy
- On Windows: install Npcap for L2 capture (https://nmap.org/npcap/)
- Create & activate venv:
python -m venv sniff_venv .\sniff_venv\Scripts\Activate.ps1 - Install dependencies:
python -m pip install scapy # optional: save deps python -m pip freeze > requirements.txt
Basic:
python sniff.pyWith options:
python sniff.py -i "<interface>" -f "tcp port 80" -c 100 -o capture.pcap -l capture.log -vOptions:
-i, --iface: interface name (optional)-f, --filter: BPF filter string (optional — if omitted, no filter applied)-c, --count: number of packets to capture (default: 5)-o, --output: pcap output path (default: packets.pcap)-l, --log: text log path (default: packets.log)-v, --verbose: show verbose packet info
The program shows a 3s banner/countdown before capturing.
- HTTP (port 80):
tcp port 80 - All TCP/UDP:
tcp or udp - DNS:
port 53 - Host:
host 192.168.0.10Note:httpalone is not a valid BPF expression.
- pcap saved to
-opath (open with Wireshark) - text log saved to
-lpath - console output is colorized (TCP/UDP)
Add a .gitignore entry to avoid pushing sniff_venv/. Example:
sniff_venv/
__pycache__/
*.py[cod]
.vscode/
.env
- If you want L2 captures on Windows, install Npcap and run Powershell/terminal as Administrator if required.
- Use a Personal Access Token or SSH key for GitHub pushes.
License: MIT (or choose one)