Skip to content

Instantly share code, notes, and snippets.

@rvazarkar
Created January 4, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvazarkar/0c1ed638db822ece1597914a9ca7db7e to your computer and use it in GitHub Desktop.
Save rvazarkar/0c1ed638db822ece1597914a9ca7db7e to your computer and use it in GitHub Desktop.
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