Skip to content

Instantly share code, notes, and snippets.

@wrobelda
Last active August 7, 2025 18:44
Show Gist options
  • Save wrobelda/403fe4e7ff542ce14a4bba9a06e40777 to your computer and use it in GitHub Desktop.
Save wrobelda/403fe4e7ff542ce14a4bba9a06e40777 to your computer and use it in GitHub Desktop.
Convert OPNHome ISC DHCP mappings to Dnsmasq CSV import
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
])
@kwazieharry
Copy link

hi, what folder is /conf/config.xml located?

@aric89
Copy link

aric89 commented Aug 6, 2025

hi, what folder is /conf/config.xml located?

On opnsense. I downloaded it right to the firewall using fetch and then ran the command that way.

fetch https://gist.githubusercontent.com/wrobelda/403fe4e7ff542ce14a4bba9a06e40777/raw/a55012cd669e1f0b20e26fb65193b7e009ca52d4/convert_opnhome_isc_to_dnsmasq_csv.py

cat /conf/config.xml | python3 convert_opnhome_isc_to_dnsmasq_csv.py > dhcp-mappings.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment