Last active
April 21, 2019 05:38
-
-
Save selvakn/7a402804bf65e9bf29a39f16ec6c1544 to your computer and use it in GitHub Desktop.
Forward DHCP events from isc-dhcp-server server
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
# Add the following snippet to your dhcpd.conf | |
commit { | |
set ClientName = pick-first-value(option fqdn.hostname, option host-name); | |
set ClientIp = binary-to-ascii(10, 8, ".", leased-address); | |
set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)); | |
execute("forward_dhcp_events.py", "commit", ClientName, ClientIp, ClientMac); | |
} | |
on release { | |
set ClientName = pick-first-value(option fqdn.hostname, option host-name); | |
set ClientIp = binary-to-ascii(10, 8, ".", leased-address); | |
set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)); | |
execute("forward_dhcp_events.py", "release", ClientName, ClientIp, ClientMac); | |
} |
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
#!/usr/bin/env python | |
import socket | |
import json | |
import os | |
import sys | |
UDP_IP = "127.0.0.1" | |
UDP_PORT = 1234 | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
message = { | |
"type": "DHCPServer", | |
"action": sys.argv[1], | |
"name": sys.argv[2], | |
"ip": sys.argv[3], | |
"mac": sys.argv[4] | |
} | |
sock.sendto(json.dumps(message) + "\n", (UDP_IP, UDP_PORT)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment