From 6ffd802b935bc7c992a04ac115fc1a7675de82c8 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Mon, 23 Dec 2013 15:05:45 +0100 Subject: [PATCH] IANA nameserver RR type converter to JSON/Python dict --- bin/rr-types.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 bin/rr-types.py diff --git a/bin/rr-types.py b/bin/rr-types.py new file mode 100644 index 0000000..aa9586c --- /dev/null +++ b/bin/rr-types.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Tool to dump in IANA RR DNS parameters in JSON or Python dict format +# +# Software is free software released under the "Modified BSD license" +# +# Copyright (c) 2013 Alexandre Dulaunoy - a@foo.be + +import argparse +import csv +import json +import codecs +import urllib.request + +#IANA format (CSV) is TYPE,Value,Meaning,Reference,Template,Registration Date +ianarrurl = "http://www.iana.org/assignments/dns-parameters/dns-parameters-4.csv" + +argParser = argparse.ArgumentParser(description='Dump IANA DNS parameters in various formats') +argParser.add_argument('-d', action='store_true', help='Python dict') +argParser.add_argument('-j', action='store_true', default=True, help='JSON output (default format)') +argParser.add_argument('-i', action='store_false', default=True, help='Disable integer value RR check') +argParser.add_argument('-v', action='store_true', help='Verbose output') +args = argParser.parse_args() + + +rrset=[row for row in csv.DictReader(codecs.iterdecode(urllib.request.urlopen(ianarrurl),'utf-8'),fieldnames = ( "Type","Value","Meaning","Reference","Template","Registration Date" ))] + +if args.i: + rri = [] + for rr in rrset[1:]: + if rr['Value'].isdigit(): + rri.append(rr) + rrset=rri +else: + rrset=rrset[1:] + +if args.d: + print (rrset) + +if args.j: + jsonout = json.dumps( rrset ) + print (jsonout)