#!/usr/bin/python # # arinnetlist.py - Query ARIN for Org info # # (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 ariniporg.py ipaddr' sys.exit(2) # Lookup the data for the IP address resturl = 'https://whois.arin.net/rest/ip/%s' % (sys.argv[1]) req = urllib2.Request(resturl, None, {'Accept': 'application/json'}) res = urllib2.urlopen(req) data = json.loads(res.read()) res.close() orgname = 'Unknown' try: orgname = data['net']['orgRef']['@name'] except: pass try: orgname = data['net']['customerRef']['@name'] except: pass print '%s,%s' % (sys.argv[1], orgname.replace(',','')) sys.exit(0)