Created
January 4, 2017 16:35
-
-
Save rvazarkar/0c1ed638db822ece1597914a9ca7db7e to your computer and use it in GitHub Desktop.
This file contains 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 bs4 import BeautifulSoup | |
import re | |
import sys | |
if (len(sys.argv) < 2): | |
print 'Usage:' | |
print 'python arinScraper.py "target"' | |
sys.exit() | |
addrs = [] | |
target = sys.argv[1] | |
print 'Searching by Organization' | |
data = {'advanced':'true','q':'*{}*'.format(target),'r':'ORGANIZATION'} | |
s = requests.Session() | |
r = s.post('https://whois.arin.net/ui/query.do', data=data) | |
soup = BeautifulSoup(r.text, 'html.parser') | |
tds = soup.find_all('td') | |
enum = [] | |
for t in tds: | |
name = str(t).split('>')[1].split('(')[0].rstrip() | |
link = t.find('a')['href'] | |
enum.append((name,link)) | |
for e in enum: | |
try: | |
r = s.get('{}/nets'.format(e[1])) | |
soup = BeautifulSoup(r.text, 'html.parser') | |
refs = soup.find_all('netref') | |
if (len(refs) > 0): | |
print e[0] | |
for ref in refs: | |
ra = '{}-{}'.format(ref['startaddress'],ref['endaddress']) | |
print ra | |
addrs.append(ra) | |
except Exception as ex: | |
print 'Failed on {}'.format(e[1]) | |
print '' | |
print 'Searching by Customer' | |
data = {'advanced':'true','q':'*{}*'.format(target),'r':'CUSTOMER'} | |
r = s.post('https://whois.arin.net/ui/query.do', data=data) | |
soup = BeautifulSoup(r.text, 'html.parser') | |
tds = soup.find_all('td') | |
enum = [] | |
for t in tds: | |
name = str(t).split('>')[1].split('(')[0].rstrip() | |
link = t.find('a')['href'] | |
enum.append((name,link)) | |
for e in enum: | |
try: | |
r = s.get('{}/nets'.format(e[1])) | |
soup = BeautifulSoup(r.text, 'html.parser') | |
refs = soup.find_all('netref') | |
if (len(refs) > 0): | |
print e[0] | |
for ref in refs: | |
ra = '{}-{}'.format(ref['startaddress'],ref['endaddress']) | |
print ra | |
addrs.append(ra) | |
except Exception as ex: | |
print 'Failed on {}'.format(e[1]) | |
print '' | |
print 'All Addresses Found:' | |
for a in addrs: | |
print a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment