Skip to content

Instantly share code, notes, and snippets.

@fakhamatia
Last active February 8, 2026 17:32
Show Gist options
  • Select an option

  • Save fakhamatia/6a5768df2cebdad58552821e160baaf9 to your computer and use it in GitHub Desktop.

Select an option

Save fakhamatia/6a5768df2cebdad58552821e160baaf9 to your computer and use it in GitHub Desktop.

📡 Device Notification Script Setup Guide (OpenWrt)

1. 🏭 Register for MAC Vendor Lookup

  • Go to macvendors.com
  • Sign up and generate your API token
  • Paste the token into the MACVENDORS_TOKEN variable inside the script

2. 🤖 Create a Telegram Bot

  • Open @BotFather on Telegram
  • Create a new bot and get the BOT_TOKEN
  • Send a message to your bot and use a tool like IDBot or logs to find your CHAT_ID
  • Fill in both BOT_TOKEN and CHAT_ID in the script

3. 💾 Save the Script

  • Save the script to the following path :
    /etc/hotplug.d/dhcp/99-notify_new_device
  • Use chmod:
    chmod +x /etc/hotplug.d/dhcp/99-notify_new_device

4. 📒 Add Known MAC Addresses

  • Create a file at:
    /etc/known_macs
  • List known MAC addresses one per line
  • You can optionally add a name or description after the MAC address:
    50:98:39:EE:1D:93    Ali's iPhone
    3C:2E:F9:1A:44:55    Office Printer
    A4:7C:94:2F:18:01    Smart TV - Living Room
    

✅ Done!

Now every time an unknown device connects to your network,
you'll get a detailed notification in Telegram 📬

#!/bin/sh
KNOWN_MACS="/etc/known_macs"
MACVENDORS_TOKEN=""
BOT_TOKEN=""
CHAT_ID=""
MAC="$MACADDR"
IP="$IPADDR"
HOSTNAME="$HOSTNAME"
[ -z "$MAC" ] && exit 0
grep -iq "$MAC" "$KNOWN_MACS" 2>/dev/null && exit 0
VENDOR=$(curl -s -G "https://api.macvendors.com/v1/lookup/${MAC}" \
-H "Authorization: Bearer ${MACVENDORS_TOKEN}" \
-H "Accept: text/plain")
if echo "$VENDOR" | grep -qE '^{.*}$' || [ -z "$VENDOR" ] || [ "$VENDOR" = "null" ]; then
VENDOR="Unknown"
fi
DATE=$(date '+%Y-%m-%d %H:%M:%S')
MESSAGE="🚨 <b>New Device Connected</b>
<b>🕒 Time:</b> $DATE
<b>💻 Hostname:</b> $HOSTNAME
<b>🌐 IP:</b> <code>$IP</code>
<b>🔍 MAC:</b> <code>$MAC</code>
<b>🏭 Vendor:</b> $VENDOR"
curl -s -X POST https://api.telegram.org/bot$BOT_TOKEN/sendMessage \
-d chat_id=$CHAT_ID \
-d parse_mode="HTML" \
-d text="$MESSAGE"
@babirich
Copy link

babirich commented Feb 8, 2026

این اسکریپت رو با چه پسوندی ذخیره کنیم؟

چه جوری به اون مسیر دسترسی پیدا کنیم؟

با ترمیوس میشه؟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment