Created
March 3, 2019 23:29
-
-
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
This file contains 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 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