Build a Python Wi-Fi Deauth Attack Detector for Your Home Network


Wi-Fi deauthentication attacks are simple, cheap, and surprisingly common. An attacker sends forged "disconnect" frames pretending to be your router, and every device on the network drops off. The frames are unauthenticated by design in older Wi-Fi standards, so the router has no way to know they are fake. It is often the first step in a bigger attack — kick everyone off, then offer a fake network with the same name and harvest passwords.

The good news: those forged frames are easy to spot. A normal network sends almost no deauth frames. A burst of them means something is wrong. This post builds a small Python detector you run on your own home network, using Scapy to listen for the frames and alert you.

What You Need

You need a Linux laptop with a Wi-Fi adapter that supports monitor mode, and Scapy installed (pip install scapy). Put your adapter into monitor mode first — on most systems that looks like:

sudo airmon-ng start wlan0

That creates a monitor interface, usually called wlan0mon. Everything below runs on your own network, with your own devices. Never point this at a network you do not own.

The Detector

A deauthentication frame is a management frame: type 0, subtype 12. The code sniffs for those frames, counts them per source, and alerts when a burst appears.

from scapy.all import sniff, Dot11, Dot11Deauth
from collections import Counter
from datetime import datetime

counter = Counter()
THRESHOLD = 10  # deauth frames in one window = suspicious

def handle(pkt):
    if pkt.haslayer(Dot11Deauth):
        src = pkt[Dot11].addr2
        counter[src] += 1
        if counter[src] == THRESHOLD:
            print(f"[{datetime.now()}] ALERT: {THRESHOLD}+ deauth frames "
                  f"from {src} — possible deauth attack!")

sniff(iface="wlan0mon", prn=handle, store=False)

Run it, leave it listening, and it prints an alert the moment any single source sends ten deauth frames. In a healthy home network you should see almost none, so even a small burst stands out.

Making It Useful

A raw alert on the terminal is a start, but you can go further. Log every event with a timestamp to a file so you can see patterns over days. Add the BSSID of your own access point and ignore deauth frames your router legitimately sends. Send yourself a message — a simple webhook or email — when the threshold trips, so the alert reaches you even if you are not watching the screen.

And the defense side matters more than the detection. If your router supports it, turn on Protected Management Frames (802.11w), which makes forged deauth frames much harder to pull off. Use WPA3 where possible, and keep your router firmware updated. Detection tells you someone tried; protected management frames stop them from succeeding.

This is a weekend project with a real payoff: a tool that watches your own airwaves and tells you the moment someone tries to knock your devices offline.

Comments

Popular Posts