Skip to content

Instantly share code, notes, and snippets.

@kenji4569
Created May 16, 2026 03:52
Show Gist options
  • Select an option

  • Save kenji4569/bf2d16923d9665eb6863b0c9885c2684 to your computer and use it in GitHub Desktop.

Select an option

Save kenji4569/bf2d16923d9665eb6863b0c9885c2684 to your computer and use it in GitHub Desktop.
Display the list of CIDRs
import re
import subprocess
ASN = "AS200373"
cmd = f"whois -h whois.radb.net -- '-i origin {ASN}'"
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True,
check=True,
)
cidrs = set()
for line in result.stdout.splitlines():
line = line.strip()
m = re.match(r"^route:\s+(.+)$", line)
if m:
cidr = m.group(1)
cidrs.add(cidr)
# m = re.match(r"^route6:\s+(.+)$", line)
# if m:
# cidr = m.group(1)
# # Exclude huge IPv6 ranges such as /29
# try:
# net = ipaddress.ip_network(cidr)
# # Exclude prefixes smaller than /32 (e.g., /31, /29)
# if net.prefixlen < 32:
# continue
# except ValueError:
# continue
# cidrs.add(cidr)
for cidr in sorted(cidrs):
print(cidr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment