Every action on a network becomes packets on the wire. A sniffer reads them — and understanding one is the fastest way to truly grasp how networks work, and why unencrypted traffic is so dangerous. This lesson uses scapy, Python's packet Swiss-army knife. Sniff only on a network you own or are authorised to monitor.
What sniffing shows you
Normally your network card ignores packets not addressed to it. A sniffer asks it to show you everything it sees — source, destination, protocol, and often the raw contents.
A five-line sniffer
from scapy.all import sniff
def show(packet):
print(packet.summary())
sniff(prn=show, count=10) # needs sudo
Run it with sudo and you'll watch real packets scroll past — DNS lookups, web requests, pings.
Looking inside a packet
from scapy.all import sniff, IP
def inspect(packet):
if packet.haslayer(IP):
print(packet[IP].src, '->', packet[IP].dst)
sniff(prn=inspect, filter='tcp', count=20)
The filter='tcp' uses BPF syntax — the same filter language as Wireshark — to grab only what you care about.
| Layer | Tells you |
|---|---|
| Ethernet | Hardware (MAC) addresses |
| IP | Source and destination IP |
| TCP/UDP | Ports, i.e. which service |
| Raw | The actual payload — plaintext if unencrypted |
Tip: This is why HTTPS matters. On open Wi-Fi, plain HTTP traffic — logins included — travels as readable text any sniffer can grab. Encryption is what turns that payload into noise. Capturing other people's traffic without authorisation is illegal — keep it to your own network.
From packets to understanding
Once you've watched your own DNS and HTTP requests fly past in plaintext, you'll never think about network security the same way — and you'll understand exactly what tools like Wireshark are showing you.