Created
February 3, 2017 09:13
-
-
Save hkwi/f6841c69a1b8dc7e9e706a52d9883de7 to your computer and use it in GitHub Desktop.
dnsmasq dhcp lease watch by inotify
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 characters
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") |
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 characters
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) |
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 characters
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