Browse Source

Generator script for asn.dn42

zorun 10 years ago
parent
commit
5d78064a95
1 changed files with 56 additions and 0 deletions
  1. 56 0
      asn-dns.py

+ 56 - 0
asn-dns.py

@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+"""This script generates DNS TXT records containing ASN information.
+
+The idea comes from asn.cymru.com.  Example:
+
+  dig +short AS1.asn.cymru.com TXT
+
+The output looks like this:
+
+  "1 | US | arin | 2001-09-20 | LVLT-1 - Level 3 Communications, Inc."
+
+In dn42, we try to respect this format. Fields 2 and 3 are set to "DN42"
+and "dn42", respectively.  The date field is left empty, as we currently
+do not record this information in the registry. For the last field, we use
+"[as-name] [descr]" from the registry.
+
+"""
+
+import sys
+import time
+
+from registry import AutNum
+
+REGISTRYPATH = "/home/zorun/net.dn42.registry"
+OUT = "/home/zorun/tmp/asn.dn42.zone"
+
+ORIGIN = "asn.dn42."
+TTL = "1h"
+NS = ["tuxmachine.polynome.dn42.", "ns1.allowed.dn42.", "ns1.pyropeter.dn42.", "beta.synhacx.dn42."]
+
+def gen_zone(registrypath, out):
+    # SOA and stuff
+    out.write("$ORIGIN {}\n".format(ORIGIN))
+    out.write("$TTL {}\n".format(TTL))
+    serial = int(time.time())
+    out.write("@ IN SOA tuxmachine.polynome.dn42. dn42.polyno.me. ({} 1d 1h 1w 5m)\n".format(serial))
+
+    # NS
+    for ns in NS:
+        out.write("@ NS {}\n".format(ns))
+
+    # TXT data
+    autnum = AutNum(registrypath)
+    for (asn, data) in autnum.data.items():
+        comment = ""
+        if "as-name" in data:
+            comment = data["as-name"][0]
+            if "descr" in data:
+                comment += " " + data["descr"][0]
+        comment.replace('"', '')
+        out.write('{} TXT "{} | DN42 | dn42 |  | {}"\n'.format(asn, asn[2:], comment))
+
+if __name__ == "__main__":
+    with open(OUT, "w") as f:
+        gen_zone(REGISTRYPATH, f)