Forked from wrobelda/convert_opnhome_isc_to_dnsmasq_csv.py
Created
May 27, 2025 18:19
-
-
Save demarey-baker/0749af7783ff52fb14df82439f3b92a8 to your computer and use it in GitHub Desktop.
Convert OPNHome ISC DHCP mappings to Dnsmasq CSV import
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 xml.etree.ElementTree as ET | |
import csv | |
import sys | |
csv_writer = csv.writer(sys.stdout) | |
# Write header | |
csv_writer.writerow([ | |
"host", "domain", "ip", "client_id", "hwaddr", | |
"lease_time", "ignore", "set_tag", "descr", "aliases" | |
]) | |
# Read entire XML config from stdin | |
xml_data = sys.stdin.read() | |
root = ET.fromstring(xml_data) | |
dhcpd = root.find('dhcpd') | |
if dhcpd is None: | |
sys.exit("No <dhcpd> section found in config.xml") | |
for iface in dhcpd: | |
for staticmap in iface.findall('staticmap'): | |
mac = staticmap.findtext('mac', '').strip() | |
ip = staticmap.findtext('ipaddr', '').strip() | |
hostname = staticmap.findtext('hostname', '').strip() | |
if mac and ip: | |
csv_writer.writerow([ | |
"", # host | |
"", # domain | |
ip, | |
"", # client_id | |
mac, | |
"", "", "", | |
hostname, # descr | |
"" # aliases | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment