#!/usr/bin/python # # arinnetlist.py - Query ARIN for netlists # # (c) 2017 Todd Shadburn # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # import os import sys import urllib2 import json if len(sys.argv) < 2: print 'Usage arinnetlist.py orgid' sys.exit(2) # Lookup the netblocks for the ORGID req = urllib2.Request('https://whois.arin.net/rest/org/AT-88-Z/nets', None, {'Accept': 'application/json'}) res = urllib2.urlopen(req) data = json.loads(res.read()) res.close() netlist = data['nets']['netRef'] # Lookup the CIDR for each netblock for i in netlist: req = urllib2.Request(i['$'], None, {'Accept': 'application/json'}) res = urllib2.urlopen(req) data = json.loads(res.read()) res.close() netblock = data['net']['netBlocks']['netBlock'] if 'startAddress' in netblock and 'cidrLength' in netblock: print '%s/%s' % (netblock['startAddress']['$'], netblock['cidrLength']['$']) sys.exit(0)