Network & Cyber DefenseTechnician

Know Every Device on Your Network

Scan your own network on a schedule and get alerts when an unknown device joins.

LevelTechnician
Time1 h
Est. cost~$28
Steps5

You cannot protect what you cannot see. A Pi can inventory your home network, remember known devices and notify you when something new appears.

⚠ SAFETY
Scanning networks you do not own or have permission to test can be illegal. Use these tools only on your own network.

Video tutorial

▶ Shannon MorseWatch on YouTube ↗

Video by Shannon Morse, embedded from YouTube. The written steps below are our own and match the parts list.

Mission steps

  1. Install nmap

    sudo apt install nmap. Only scan networks you own or have written permission to test.

  2. Run a discovery scan

    nmap -sn 192.168.1.0/24 lists live hosts and, run with sudo, their MAC addresses.

  3. Save known devices

    Run the script once to record your current devices, then label them.

  4. Alert on new ones

    Schedule the script every 15 minutes with cron; it sends a notification for any unknown MAC.

  5. Act

    Unknown device? Check your router, change your Wi-Fi password and move smart gadgets to a guest network.

Code

# netwatch.py — run with sudo for MAC addresses
import subprocess, re, json, os, requests
NET, DB = "192.168.1.0/24", "/home/maker/known.json"
TOPIC = "https://ntfy.sh/mc-net-k3j9d8"      # your own random topic

out = subprocess.run(["nmap", "-sn", NET], capture_output=True, text=True).stdout
seen = set(m.upper() for m in re.findall(r"MAC Address: ([0-9A-Fa-f:]{17})", out))
known = set(json.load(open(DB))) if os.path.exists(DB) else set()

if not known:
    json.dump(sorted(seen), open(DB, "w"), indent=1)
    print("Saved", len(seen), "known devices")
else:
    for mac in seen - known:
        requests.post(TOPIC, data=f"New device on network: {mac}")

Tip: test every script on the bench before installing it in a moving machine.

Questions

Why do phones show up as new devices?

Modern phones use a random private MAC per network. Turn it off for your home Wi-Fi or add the new MAC once.