How to get notified of newly connected devices on your OpenWRT router

how-to-get-notified-of-newly-connected-devices-on-your-openwrt-router

So you’ve just set up OpenWRT with all the bells and whistles only to realize there is no out-of-the-box way to receive notifications for newly connected devices. No worries! With this tutorial, we will set up our OpenWRT server to send notifications to Pushover whenever a new device is connected to the server.

Let’s start with Pushover. Sign up is really easy, and pricing is very reasonable. It’s typically a one-time purchase per device used. For myself, I’ve purchased it for my iPhone and really enjoy its simplicity. Once signed up, create a new application with your preferred options. Lastly, find your app’s api key along with your user key. They should look something like this:

API Key
User Key

With pushover ready to go, let’s head back to our OpenWRT server. Create a new script file called new_device_notification.sh with the following lines:

#!/bin/sh

cat << "EOF" > /etc/hotplug.d/dhcp/90-newdev
[ "$ACTION" == "add" ] || exit 0
# [ "$ACTION" == "add" -o "$ACTION" == "update" ] || exit 0
known_macs="https://dev.to/etc/known_macs"
user_key="your-user-key"
api_key="your-api-key"
if ! /bin/grep -iq "$MACADDR" "$known_macs"; then
  msg="New device detected:
MAC: $MACADDR
IP: $IPADDR
Hostname: $HOSTNAME"
  echo "$MACADDR $IPADDR $HOSTNAME" >> /etc/known_macs
  curl -s 
       --form-string "token=$api_key" 
       --form-string "user=$user_key" 
       --form-string "title=New Device" 
       --form-string "message=$msg" 
       https://api.pushover.net/1/messages.json
fi
exit 0
EOF

Replace your-api-key and your-user-key with the values provided from Pushover. This script will check for new devices on your DHCP server as these devices make connections. If the server has not seen it before, it will add the device to a list of known devices and send you a notification.

Finally, let’s make this script runnable and execute it:

chmod +x new_device_notification.sh
./new_device_notification.sh

And that’s it! Simply restart your server and you should begin receiving messages from Pushover. You may receive many messages at the beginning as existing devices are added, but from then on, only new devices will trigger a message.

Enjoy!

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
is-openai’s-custom-gpt-the-next-frontier?

Is OpenAI’s Custom GPT the Next Frontier?

Next Post
treat-your-audience-like-your-marketing-database?-that’s-a-mistake

Treat Your Audience Like Your Marketing Database? That’s a Mistake

Related Posts