Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Converts Un*x's /etc/ethers & /etc/hosts to OpenWRT's /etc/config/dhcp
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Converts /etc/ethers & /etc/hosts to OpenWRT's /etc/config/dhcp
# Copyright (C) 2019 Krzysztof Burghardt <>
# License: CC-BY
ENTRY = """config host
option name '{0}'
option dns '1'
option mac '{1}'
option ip '{2}'
with open("hosts") as hf:
for line in hf:
l = line.split()
ip = l[0]
hostname = l[1]
for ether in open("ethers"):
if hostname in ether:
l = ether.split()
mac = l[0]
print(ENTRY.format(hostname, mac, ip))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment