What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Script to notify unknown device connects to LAN

Col8eral

Senior Member
Does anyone know of a script that can send a notification email when an unknown device connects to the LAN. So, if the device IP/MAC is known already then no notification is sent. Something along those lines.
 
Did you search? 😁

I recall that was discussed here before.
 
Looks like the app will do this for you:
Link
 
Thanks guys. Much appreciated. I have set app notifications, which does work, but I would like a script to send emails if possible.

I did do a search, but didnt manage to find much. I found this script, but doesnt work on ASUS routers as far as I can tell. If there's anyone who has the skills, could this be modified to work:

Code:
#!/bin/sh
# script to detect new DHCP lease
# this will be called by dnsmasq every time a new device is connected
# with the following arguments
# $1 = add | old
# $2 = MAC address
# $3 = IP address
# $4 = device name

notification_email="####@gmail.com"
known_mac_addr="/etc/storage/known_mac_addr.txt"

# check if the MAC is in known devices list
grep -q "$2" "$known_mac_addr"
unknown_mac_addr=$?

if [ "$1" == "add" ] && [ "$unknown_mac_addr" -ne 0 ]; then
msg="New device on `nvram get system.@system[0].hostname`.`nvram get dhcp.@dnsmasq[0].domain` $*"
echo `date` $msg >> /tmp/dhcpmasq.log
# encode colon (:) and form e-mail
echo "To:"$notification_email > /tmp/email.txt
echo "From:"$notification_email >> /tmp/email.txt
echo "Subject:A new device appears in the home network" >> /tmp/email.txt
echo $msg | sed s/:/-/g >> /tmp/email.txt
sendmail "###@gmail.com" -H 'exec openssl s_client -quiet -tls1_2 -connect smtp.gmail.com:465' < /tmp/email.txt -au"####@gmail.com" -ap"pass###" -f "####@gmail.com"
fi
 
Similar threads
Thread starter Title Forum Replies Date
A Example script for guest network ASUS Wi-Fi 14

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top