Skip to content

Instantly share code, notes, and snippets.

@Jcpetrucci
Last active January 23, 2018 08:22
Show Gist options
  • Save Jcpetrucci/445039cfb686124cc785 to your computer and use it in GitHub Desktop.
Save Jcpetrucci/445039cfb686124cc785 to your computer and use it in GitHub Desktop.
Unseen DHCP client alert (DD-WRT)
#!/bin/sh
# Generates a syslog message w/ prio=emerg for any DHCP client we haven't seen since last reboot.
# Note: Syslog server is configured to send SMTP on any event >= emerg. This script alone does not send the mail.
echo '#!/bin/sh
op="${1:-op}"
mac="${2:-mac}"
ip="${3:-ip}"
hostname="${4}"
grep "$mac" /tmp/dnsmasq-leases.log || { export priority=emerg; echo "$mac" "$hostname" >> /tmp/dnsmasq-leases.log; }
logger -t "DHCP-Lease" -p ${priority:-info} "${op} ${mac} ${ip} ${hostname}"' > /tmp/dhcp-script.sh
chmod +x /tmp/dhcp-script.sh
echo 'dhcp-script=/tmp/dhcp-script.sh' >> /tmp/dnsmasq.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment