Last active
November 2, 2016 19:16
-
-
Save adamenger/e56e007f901f68a3580ef8c105ac7f4a 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 | |
# Example ./subnet_finder.py https://whois.arin.net/rest/org/DROPB/nets | |
from BeautifulSoup import BeautifulSoup | |
import requests | |
import sys | |
# Spoof your agent here | |
user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36" | |
# Set the user agent and accept headers, accept is required otherwise arin.net will return xml | |
headers = { | |
'User-Agent': user_agent, | |
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" | |
} | |
# Grab the network page html, pull out the subnets and print them | |
def getSubnet(network_url): | |
subnet_request = requests.get(network_url, headers=headers).text | |
netblocks = BeautifulSoup(subnet_request).findAll('td') | |
print netblocks[3].text | |
def main(): | |
# Grab url from arg 1 | |
url = sys.argv[1] | |
# Make our actual request to get all links to the networks | |
request = requests.get(url, headers=headers).text | |
# Grab all the links on the page | |
netblocks = BeautifulSoup(request).table.findAll('a') | |
# Loop through all the network links on the main page | |
for block in netblocks: | |
subnet = block['href'] | |
getSubnet(subnet) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print "Usage: ./subnet_finder.py https://whois.arin.net/rest/org/DROPB/nets" | |
exit() | |
else: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment