Last active
July 24, 2022 19:41
-
-
Save joshspicer/e09c3158074cdd584c79e2bb5bd4e640 to your computer and use it in GitHub Desktop.
[OpenWrt] Telegram alert when a new wireless device associates with access point. (http://spcr.me/openwrt-alert)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Alerts via telegram when a new device joins OpenWRT wireless interface | |
# write-up at: spcr.me/openwrt-alert | |
# | |
# ~ note ~ | |
# Call from in /etc/rc.local | |
TELEGRAM="https://api.telegram.org/bot<YOUR_API_KEY>/sendMessage?chat_id=<YOUR_CHAT_ID_HERE>&text=" | |
REBOOTTEXT="Router has rebooted" | |
msg=`/usr/bin/curl "$TELEGRAM$REBOOTTEXT"` | |
# Avoid race condition | |
sleep 20 | |
/usr/sbin/hostapd_cli -a/root/associated.sh -B -iwlan0 | |
/usr/sbin/hostapd_cli -a/root/associated.sh -B -iwlan1 | |
/usr/sbin/hostapd_cli -a/root/associated.sh -B -iwlan1-1 | |
/root/manual_alert.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Alerts via telegram when a new device joins OpenWRT wireless interface | |
# write-up at: spcr.me/openwrt-alert | |
# | |
# ~ note ~ | |
# Depends on hostapd_cli | |
TELEGRAM="https://api.telegram.org/bot<YOUR_API_KEY_HERE>/sendMessage?chat_id=<YOUR_CHAT_ID_HERE>&text=" | |
# hotapd_cli event vars | |
# $1 = interface | |
# $2 = action | |
# $3 = MAC Addr | |
if grep "^$3$" /root/seen.txt | |
then | |
# echo "Have seen $3" | |
continue | |
else | |
# echo "Have not seen $3" | |
manufact=`/usr/bin/curl "https://api.macvendors.com/$3"` | |
TEXT="New Device $3 ($manufact) detected on interface $1" | |
msg=`/usr/bin/curl "$TELEGRAM$TEXT"` | |
echo "$3" >> /root/seen.txt | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Alerts via telegram when a new device joins OpenWRT wireless interface | |
# write-up at: spcr.me/openwrt-alert | |
# | |
TELEGRAM="https://api.telegram.org/bot<YOUR_API_KEY>/sendMessage?chat_id=<YOUR_CHAT_ID>&text=" | |
REBOOTTEXT="Manual Scan" | |
msg=`/usr/bin/curl "$TELEGRAM$REBOOTTEXT"` | |
for interface in `iwinfo | grep ESSID | cut -f 1 -s -d" "` | |
do | |
macaddrs=`iwinfo $interface assoclist | grep dBm | cut -f 1 -s -d" "` | |
for mac in $macaddrs | |
do | |
# Ignore occasional bad output of cut | |
reqsubstr="freq" | |
if [ -z "${mac##*$reqsubstr*}" ] ;then | |
continue | |
fi | |
# Check against our log of "seen" MAC addresses | |
if grep -i "^$mac$" /root/seen.txt > /dev/null | |
then | |
echo "Have seen '$mac'" | |
continue | |
else | |
echo "Have not seen '$mac'" | |
manufact=`/usr/bin/curl "https://api.macvendors.com/$mac"` | |
TEXT="New device $mac ($manufact) manually detected on interface $interface" | |
msg2=`/usr/bin/curl "$TELEGRAM$TEXT"` | |
echo "$mac" >> /root/seen.txt | |
fi | |
done | |
done |
hi ,
script not working
https://joshspicer.com/openwrt-alert
msg=/usr/bin/curl "$TELEGRAM$REBOOTTEXT"
curl: (3) Error
help pls
hi ,
script not working
https://joshspicer.com/openwrt-alert
msg=
/usr/bin/curl "$TELEGRAM$REBOOTTEXT"
curl: (3) Errorhelp pls
Hello, you can check my fork with the issue fixed https://gist.github.com/ksverdlov/33a26fed4c4413171171de86ba59c74f
Where's the associated.sh file?
I'm not the author, but I think that it should be /root/event_alert.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where's the associated.sh file?