Last active
June 25, 2025 01:12
-
Star
(113)
You must be signed in to star a gist -
Fork
(16)
You must be signed in to fork a gist
-
-
Save jwalanta/53f55d03fcf5265938b64ffd361502d5 to your computer and use it in GitHub Desktop.
Revisions
-
jwalanta revised this gist
Jan 23, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,7 @@ if [ "$1" == "add" ]; then echo `date` $msg >> /tmp/dhcpmasq.log # encode colon (:) and send email echo $msg | sed s/:/-/g | sendmail "$notification_email" fi ``` @@ -64,7 +64,7 @@ if [ "$1" == "add" ] && [ "$unknown_mac_addr" -ne 0 ]; then echo `date` $msg >> /tmp/dhcpmasq.log # encode colon (:) and send email echo $msg | sed s/:/-/g | sendmail "$notification_email" fi ``` -
jwalanta revised this gist
Jan 23, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -68,4 +68,4 @@ if [ "$1" == "add" ] && [ "$unknown_mac_addr" -ne 0 ]; then fi ``` When a new device is added, dnsmasq calls `detect_new_device.sh` with arguments `add mac_addr ip_addr devicename`. The script checks if the device is new (if the dhcp lease hasn't expired, it calls with `old`), then logs and emails (which eventually is a text message) the information. -
jwalanta revised this gist
Jan 23, 2017 . 1 changed file with 46 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,8 +18,53 @@ Reference: # script to detect new dhcp lease # this will be called by dnsmasq everytime a new device is connected # with the following arguments # $1 = add | old # $2 = mac address # $3 = ip address # $4 = device name notification_email="[email protected]" if [ "$1" == "add" ]; then msg="New device on `uci get system.@system[0].hostname`.`uci get dhcp.@dnsmasq[0].domain` $*" echo `date` $msg >> /tmp/dhcpmasq.log # encode colon (:) and send email echo $msg | sed s/:/%3A/g | sendmail "$notification_email" fi ``` #### Alternative script using whitelist This script only sends alerts if the mac address is not in the list ``` #!/bin/sh # script to detect new dhcp lease # this will be called by dnsmasq everytime a new device is connected # with the following arguments # $1 = add | old # $2 = mac address # $3 = ip address # $4 = device name known_mac_addr="/etc/known_mac_addr" notification_email="[email protected]" # 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 `uci get system.@system[0].hostname`.`uci get dhcp.@dnsmasq[0].domain` $*" echo `date` $msg >> /tmp/dhcpmasq.log # encode colon (:) and send email echo $msg | sed s/:/%3A/g | sendmail "$notification_email" fi ``` -
jwalanta revised this gist
Jan 22, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,17 @@ ### Add the following line in `/etc/dnsmasq.conf` `dhcp-script=/etc/detect_new_device.sh` ### Setup sendmail to send email to your text number. Reference: - https://wiki.openwrt.org/doc/howto/smtp.client - https://fixmynix.com/send-mail-command-line-linux-openwrt/ - http://lifehacker.com/5506326/how-can-i-send-an-email-via-text-message ### Create `/etc/detect_new_device.sh` with the following content ``` #!/bin/sh -
jwalanta revised this gist
Jan 22, 2017 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,17 @@ * Add the following line in /etc/dnsmasq.conf `dhcp-script=/etc/detect_new_device.sh` * Setup sendmail to send email to your text number. Reference: - https://wiki.openwrt.org/doc/howto/smtp.client - https://fixmynix.com/send-mail-command-line-linux-openwrt/ - http://lifehacker.com/5506326/how-can-i-send-an-email-via-text-message * Create `/etc/detect_new_device.sh` with the following content ``` #!/bin/sh -
jwalanta revised this gist
Jan 22, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ ## Add the following line in /etc/dnsmasq.conf `dhcp-script=/etc/detect_new_device.sh` ## Setup sendmail to send email to your text number. Reference - https://wiki.openwrt.org/doc/howto/smtp.client - https://fixmynix.com/send-mail-command-line-linux-openwrt/ - http://lifehacker.com/5506326/how-can-i-send-an-email-via-text-message ## Create `/etc/detect_new_device.sh` with the following content ``` #!/bin/sh -
jwalanta created this gist
Jan 22, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # Add the following line in /etc/dnsmasq.conf `dhcp-script=/etc/detect_new_device.sh` # Setup sendmail to send email to your text number. Reference - https://wiki.openwrt.org/doc/howto/smtp.client - https://fixmynix.com/send-mail-command-line-linux-openwrt/ - http://lifehacker.com/5506326/how-can-i-send-an-email-via-text-message # Create `/etc/detect_new_device.sh` with the following content ``` #!/bin/sh # script to detect new dhcp lease if [ "$1" == "add" ]; then echo "New device on `uci get system.@system[0].hostname`.`uci get dhcp.@dnsmasq[0].domain` $* `date`" | tee -a /tmp/dhcpmasq.log | sed s/:/%3A/g | sendmail [email protected] fi ``` When a new device is added, dnsmasq calls `detect_new_device.sh` with arguments `add mac_addr ip_addr devicename`. We check if the device is new (if the dhcp lease hasn't expired, it calls with `old`), then logs and emails (which eventually is a text message) the information.