Skip to content

Instantly share code, notes, and snippets.

@burghardt
Created March 3, 2019 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burghardt/d97fa4196ca4cd99bb706e8cebc05231 to your computer and use it in GitHub Desktop.
Save burghardt/d97fa4196ca4cd99bb706e8cebc05231 to your computer and use it in GitHub Desktop.
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 <krzysztof@burghardt.pl>
# 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