1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-22 23:20:41 +08:00
NeoNetwork/scripts/dns-generator.py

32 lines
839 B
Python
Raw Normal View History

#!/usr/bin/env python3
import sys
from pathlib import Path
import toml
from rfc2317 import gen_reverse_pointers
RESOLVE_FILE = Path("dns", "db.10.127")
RFC2317_FILE = Path("dns", "rfc2317.toml")
def iter_rfc2317_entry():
entries = toml.loads(RFC2317_FILE.read_text())
for (route, attributes) in entries.items():
2021-04-14 20:15:56 +08:00
ns = attributes.get('NS')
ds = attributes.get('DS', list())
ttl = attributes.get('TTL', -1)
yield(route, ns, ds, ttl)
def main():
orignal = RESOLVE_FILE.read_text()
records = [orignal, "; AUTOGENERATED"]
records.extend(("", "; rfc2317"))
2021-04-14 20:15:56 +08:00
for route, ns, ds, ttl in iter_rfc2317_entry():
records.extend(gen_reverse_pointers(route, ns, ds, ttl))
records.append("")
RESOLVE_FILE.write_text("\n".join(records))
if __name__ == "__main__":
main()