#!/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
| Thread starter | Title | Forum | Replies | Date |
|---|---|---|---|---|
| S | mount in script post-mount can not work | ASUS Wi-Fi | 1 |
We use essential cookies to make this site work, and optional cookies to enhance your experience.