Skip to content

Instantly share code, notes, and snippets.

@hkwi
Created February 3, 2017 09:13
Show Gist options
  • Save hkwi/f6841c69a1b8dc7e9e706a52d9883de7 to your computer and use it in GitHub Desktop.
Save hkwi/f6841c69a1b8dc7e9e706a52d9883de7 to your computer and use it in GitHub Desktop.
dnsmasq dhcp lease watch by inotify
import dbus
dnsmasq = dbus.SystemBus().get_object("uk.org.thekelleys.dnsmasq", "/uk/org/thekelleys/dnsmasq")
dnsmasq.AddDhcpLease("192.168.0.12","00:11:22:33:44:55",dbus.ByteArray(),dbus.ByteArray(),dbus.UInt32(5),dbus.UInt32(0),False)
dnsmasq.DeleteDhcpLease("192.168.0.12")
import eventlet_inotifyx as inotify
fd = inotify.init()
wd = inotify.add_watch(fd, "/var/run/dnsmasq/lease.txt")
while True:
for ev in inotify.get_events(fd):
if ev.wd == wd:
print(ev)
Vagrant.configure("2") do |config|
config.vm.box = "minimal/xenial64"
config.vm.provision "file", source: "listener.py", destination: "listener.py"
config.vm.provision "file", source: "hook.py", destination: "hook.py"
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y python-pip python-dbus dnsmasq
pip install eventlet-inotifyx
echo "enable-dbus" >> /etc/dnsmasq.d/ix.conf
echo "dhcp-range=192.168.0.2,192.168.0.31" >> /etc/dnsmasq.d/ix.conf
echo "dhcp-leasefile=/var/run/dnsmasq/lease.txt" >> /etc/dnsmasq.d/ix.conf
systemctl restart dnsmasq
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment