Skip to content

Commit

Permalink
Updates the source of AS numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-k committed May 2, 2023
1 parent d6d88e1 commit 0bd1f34
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions harpoon/commands/ip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /usr/bin/env python
import glob
import os
import re
import shutil
import socket
import subprocess
Expand Down Expand Up @@ -56,26 +55,24 @@ def add_arguments(self, parser):
def update(self):
print("Downloading AS data")
file_name, headers = urllib.request.urlretrieve(
"http://www.cidr-report.org/as2.0/autnums.html"
"https://ftp.ripe.net/ripe/asnames/asn.txt"
)
if os.path.isfile(self.asnname):
os.remove(self.asnname)
fin = open(file_name, "r", encoding="latin-1", errors="ignore")
fout = open(self.asnname, "w+")
line = fin.readline()
reg = re.compile(
r'^<a href="/cgi-bin/as-report\?as=AS\d+&view=2.0">AS(\d+)\s*</a> (.+)$'
)
while line != "":
res = reg.match(line)
if res:
fout.write("%s|%s\n" % (res.group(1), res.group(2)))
asn = line.split(" ")[0]
asname = " ".join(line.split(" ")[1:]).strip()
fout.write("{}|{}\n".format(asn, asname))
line = fin.readline()
fin.close()
fout.close()

print("Downloading CIDR data")
try:
if os.path.isfile(self.asncidr):
os.remove(self.asncidr)
except OSError:
pass
os.chdir("/tmp")
subprocess.call(["pyasn_util_download.py", "--latest"])
ls = glob.glob("rib*.bz2")[0]
Expand Down

0 comments on commit 0bd1f34

Please sign in to comment.