Skip to content

Instantly share code, notes, and snippets.

@Ara4Sh
Created March 20, 2022 17:17
Show Gist options
  • Save Ara4Sh/55b1a8cb10cf68aa2b688cc9a337504f to your computer and use it in GitHub Desktop.
Save Ara4Sh/55b1a8cb10cf68aa2b688cc9a337504f to your computer and use it in GitHub Desktop.
many years ago I used this script to extract the BGP names from HE.com I dont know if it works or not.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
class He:
def __init__(self, url="https://bgp.he.net"):
self.url = url
# Open headless chromedriver
def start_driver(self):
PROXY="socks5://127.0.0.1:1188"
# chrome options
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--window-size=1920,1080")
# options.add_argument("--proxy-server=%s" % PROXY)
options.add_argument("--user-agent=Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0")
# initiate browser
print("Starting Chrome Webdriver")
self.driver = webdriver.Chrome(options=options)
time.sleep(2)
# Close chromedriver
def stop_driver(self):
print("Stopping Chrome Webdriver")
self.driver.quit()
def get(self, as_name=None):
print("Getting {}/{}".format(self.url, as_name))
#self.driver.add_cookie({'name' : '_bgp_session', 'value' : 'BAh7BjoPc2Vzc2lvbl9pZEkiJTJmZGY5ODA4OTM1OGFiMmI1YzQwMTRmZmNjMzM1OGM2BjoGRUY%3D--3d56fcb35272524eb97e1b8913cbcfcbe5f56903'})
self.driver.get("{}/{}".format(self.url, as_name))
time.sleep(5)
links = self.driver.find_elements_by_xpath("/html/body/div[2]/div[@id='prefixes']/table/tbody/tr/td/a")
# links = self.driver.find_elements_by_tag_name('a')
ip_list = []
for i in links:
try:
ip = i.get_attribute('href')
if '/net/' in ip:
ip_list.append(ip.replace("https://bgp.he.net/net/",""))
except:
print('ignoring URL')
print(f"ip_list = {ip_list}")
return ip_list
he = He()
as_list = [
'AS49666 ',
'AS42440']
he.start_driver()
for as_name in as_list:
he.get(as_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment