After that night, the one where Nmap revealed a ghostly guest on my WiFi, I couldn't shake the feeling. I kept wondering: What if new devices join while I'm asleep? I didn't want to turn into a full-time network detective, staring at IP logs over midnight coffee.
So I did what any lazy-but-resourceful tech person would do, I automated the paranoia.
The Problem: I Didn't Want to Keep Checking
Manually scanning my network every day was fine for a while. But soon, it became another chore. Like locking your doors 12 times before bed. Necessary, but exhausting.
Then I realized, if hackers automate attacks, why can't I automate defense?
That thought changed everything.
Step 1: Write the Watchdog Script
Here's where the magic begins. A few lines of Bash can turn your machine into a 24/7 sentry.
#!/bin/bash
# network_guardian.sh
# Fatiha's home network watchdog 🕵️♀️
NETWORK="192.168.1.0/24"
LOG_DIR="$HOME/nmap_logs"
NEW_LOG="$LOG_DIR/current_scan.txt"
OLD_LOG="$LOG_DIR/previous_scan.txt"
mkdir -p $LOG_DIR
# Run scan
nmap -sn $NETWORK -oN $NEW_LOG
# Compare with previous
if [ -f "$OLD_LOG" ]; then
DIFF=$(diff $OLD_LOG $NEW_LOG)
if [ "$DIFF" != "" ]; then
echo "⚠️ New devices detected on your network!" | mail -s "Nmap Alert" [email protected]
echo "$DIFF" >> $LOG_DIR/alerts.log
fi
fi
# Update baseline
cp $NEW_LOG $OLD_LOGThat's it. One humble shell script that runs a scan, compares it with yesterday's results, and emails you if there's a surprise visitor.
Step 2: Schedule It Like a Pro
Automation means you don't touch it again, ever.
Type this into your terminal:
crontab -eAnd add:
0 3 * * * /home/username/network_guardian.shThis runs your script every night at 3 AM, quietly scanning, logging, and reporting while you dream.
Step 3: Add a Touch of Style (Because Why Not?)
Let's be honest, getting plain text alerts is boring.
I wanted drama.
So I used notify-send for desktop popups and even integrated Telegram alerts using a bot token.
Here's the Telegram snippet you can add:
curl -s -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage" \
-d chat_id=<YOUR_CHAT_ID> \
-d text="⚠️ Alert: New device joined your Wi-Fi. Stay sharp!"Boom. Now, your phone pings you the second a stranger's phone connects to your network.
Step 4: Visualize Like a Hacker Movie
If you're like me, you love dashboards. I took it one step further by piping results into a simple dashboard using Grafana + InfluxDB.
It showed device count trends, average scan durations, and "network anomalies" like spikes in new connections. One glance, and I could tell if something odd happened while I was offline.
"Visualization turns paranoia into insight." Some sleepless security engineer
The Real Payoff: Peace of Mind in a Noisy World
The first week I ran this automation, I slept better. Not because I stopped worrying, but because I delegated the worry to code.
Each morning, I'd check my inbox. No alerts? Perfect. Alerts? Then it's coffee + investigation time.
And once, I did get one. My smart TV had reconnected under a new IP, harmless, but the feeling of catching it instantly? Unmatched.
The Broader Lesson
Cybersecurity isn't just for hackers or engineers. It's for anyone who owns a Wi-Fi password.
Automation is how you stay human while your defenses stay vigilant. You don't need million-dollar firewalls. You just need a mindset: proactive, not reactive.
Pro Tip
"Security isn't about control. It's about awareness, and awareness can be automated."
Final Thoughts
The night I first ran Nmap, I discovered curiosity. The night I automated it, I discovered peace.
And now, while my code stands guard, I sleep knowing that if the digital ghosts ever return, I'll be the first to know.