Created
April 10, 2020 16:17
-
-
Save bng44270/3dea88e72ec800ce0a80c1472bb08b53 to your computer and use it in GitHub Desktop.
Use ARIN to translate ASN to IP address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from arguments import Arguments | |
from sys import argv as command_args | |
arinjson = lambda x : requests.get("http://whois.arin.net/ui/query.do?queryinput={}".format(x),headers={"Accept":"application/json"},verify=False).json() | |
ARGS = Arguments(command_args) | |
if not ARGS.Get('a'): | |
print "usage: asn2ip.py -a <ASN>" | |
else: | |
data = arinjson(ARGS.Get('a')) | |
neturl = str("{}/nets".format(data['ns4:pft']['org']['ref']['$'])) | |
resp = requests.get(neturl,headers={'Accept':'application/json'}).json() | |
for net in resp['nets']['netRef']: | |
print "{}-{} ({})".format(net['@startAddress'],net['@endAddress'],net['$']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment