What's new

Custom Script event for new LAN/WLAN clients (dhcp)?

  • 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!

Stefan1200

Occasional Visitor
I saw in the documentation that a user script for an dhcpc-event is possible. But the documentation talks about DHCP events on the WAN interface. Is there something related for LAN/WLAN clients, or did I misunderstand the documentation?

I want to create something like a user script, which sends me a mail that a new DHCP client was connected to my LAN, maybe with information like IP address and more, if possible.
 
I suppose logging as a DHCP client (WAN) is plausible, but it makes more sense in the context of a DHCP server (LAN), which is what dhcp-script does.

In my case, a "dhcp-script=" definition had not already been defined in /etc/dnsmasq.conf
Code:
# cat /jffs/scripts/dnsmasq.postconf
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh
pc_append "dhcp-host=00:24:e4:5f:00:00,192.168.66.110,Therm" $CONFIG
pc_append "dhcp-host=00:24:e4:5c:00:00,192.168.66.111,Scale" $CONFIG
pc_delete "dhcp-option=dnsf5" $CONFIG
pc_delete "dhcp-option=dnsf6" $CONFIG
pc_append "dhcp-script=/jffs/scripts/log-dhcp.sh" $CONFIG
pc_append "neg-ttl=3600" $CONFIG
pc_delete "no-negcache" $CONFIG
pc_delete "servers-file=/tmp/resolv.dnsmasq" $CONFIG
#
. /opt/share/diversion/file/post-conf.div # Added by Diversion
I only wanted DHCP events to be logged by the syslog daemon.
Code:
# cat /jffs/scripts/log-dhcp.sh
#!/bin/sh
myscriptname=$(/usr/bin/basename $0)
/usr/bin/logger -t ${myscriptname} -p local6.info "Action $1, MAC $2, IP_address $3, Hostname $4"
 
If your router already has a "dhcp-script=" definition in /etc/dnsmasq.conf, then
  • Use pc_replace instead of pc_append
  • At the end of your script call whatever the existing dhcp-script had been calling
 
Thanks for all your hints, I will check this out soon. :)
 

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!
Top