Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert RIPE DB domain dump into Fred-akm data file
#!/usr/bin/env python3
import gzip
import hashlib
import sys
from collections import defaultdict
def read_db_dump(fname="ripe.db.domain.gz"):
obj = None
with gzip.open(fname) as inf:
for line in inf:
comindex = line.find(b"#")
if comindex > 0:
line = line[:comindex]
if line.strip() == b"":
if obj:
yield obj
obj = defaultdict(list)
obj["domain"] = ""
if b":" not in line:
continue
k, v = line.split(b":", 1)
k = k.decode("ascii")
v = v.strip()
if k in ["domain", "nserver", "ds-rdata"]:
v = v.decode("ascii")
if k == "domain":
obj[k] = v
else:
obj[k].append(v)
if obj:
yield obj
def hash_domain_id(domain):
md5 = hashlib.md5(domain.encode("ascii")).digest()
return str(int.from_bytes(md5, "little") & 0xffffff)
def get_fred_akm_config(objects):
for o in objects:
line = [hash_domain_id(o["domain"]), o["domain"]]
if "ds-rdata" in o:
line.append("secure-noauto")
else:
line.append("insecure")
for ns in o["nserver"]:
yield " ".join([ns, *line])
def main():
for l in get_fred_akm_config(read_db_dump()):
print(l)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.