1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/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)
|