From 84df70578ee99bf75d6bc522444a8b8ded01a210 Mon Sep 17 00:00:00 2001 From: Anton Volnuhin Date: Sat, 18 Mar 2023 17:47:15 +0300 Subject: [PATCH] twitter from arin whois --- twitter/downloader.sh | 2 ++ utils/arin-org.py | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 utils/arin-org.py diff --git a/twitter/downloader.sh b/twitter/downloader.sh index 7660d990..b5fc7787 100644 --- a/twitter/downloader.sh +++ b/twitter/downloader.sh @@ -23,6 +23,8 @@ get_routes 'AS35995' >> /tmp/twitter.txt || echo 'failed' get_routes 'AS54888' >> /tmp/twitter.txt || echo 'failed' get_routes 'AS63179' >> /tmp/twitter.txt || echo 'failed' +python utils/arin-org.py TWITT >> /tmp/twitter.txt + # save ipv4 grep -v ':' /tmp/twitter.txt > /tmp/twitter-ipv4.txt diff --git a/utils/arin-org.py b/utils/arin-org.py new file mode 100644 index 00000000..d8be6536 --- /dev/null +++ b/utils/arin-org.py @@ -0,0 +1,61 @@ +# Import requests for making API calls +import requests + +# Import netaddr for manipulating CIDRs +import netaddr + +# Import sys for accessing command line arguments +import sys + +# Check if an org_handle was provided as a command line argument +if len(sys.argv) > 1: + # Get the org_handle from the first argument + org_handle = sys.argv[1] +else: + # Print an error message and exit if no org_handle was given + print("Please provide an organization handle as a command line argument.") + sys.exit(1) + +# Define the base URL for ARIN's Whois-RWS API +base_url = "https://whois.arin.net/rest/" + +# Define the headers for requesting XML data +headers = {"Accept": "application/xml"} + +# Make a GET request to get the networks for the organization +response = requests.get(base_url + "org/" + org_handle + "/nets", headers=headers) + +# Check if the response status code is 200 (OK) +if response.status_code == 200: + # Parse the XML data from the response + xml_data = response.text + + # Initialize an empty list for storing CIDRs + cidrs = [] + + # Loop through each network element in the XML data + for net in xml_data.split("