Last active
January 22, 2019 07:29
-
-
Save jabb3rd/e4a85811c442113d46a4688efb55e1d8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import json | |
import sys | |
asn_file = 'asn.json' | |
if len(sys.argv) < 2: | |
print('Usage: %s <name> [country]' % sys.argv[0]) | |
exit(1) | |
if len(sys.argv) > 3: | |
print('Too many arguments!') | |
exit(1) | |
print('[*] Loading AS list from %s...' % asn_file) | |
with open(asn_file, 'r') as f: | |
asns = json.loads(f.read()) | |
print('[*] Read %s AS entries' % len(asns)) | |
country = None | |
if len(sys.argv) == 3: | |
country = sys.argv[2] | |
if len(sys.argv) > 1: | |
request = sys.argv[1] | |
for k, v in asns.items(): | |
if country is not None: | |
if country.lower() in v['Country'].lower() and request.lower() in v['Name'].lower(): | |
print('%s\t%s\t%s' % (k, v['Country'], v['Name'])) | |
else: | |
if request.lower() in v['Name'].lower(): | |
print('%s\t%s\t%s' % (k, v['Country'], v['Name'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment