Skip to content

Instantly share code, notes, and snippets.

@homelinen
Created January 28, 2016 12:27
Show Gist options
  • Save homelinen/92d8f46019d4e321a815 to your computer and use it in GitHub Desktop.
Save homelinen/92d8f46019d4e321a815 to your computer and use it in GitHub Desktop.
Horrible quick script to scrape RIPE Json files
import netaddr
import json
# Parse IPs to CIDR ranges from https://apps.db.ripe.net/search/query.html#resultsAnchor
def iprange_to_cidr(ip_value):
r = ip_value.split(' - ')
print(r)
return netaddr.iprange_to_cidrs(r[0], r[1])
def get_cidrs(j):
cidrs = []
for obj in j['objects']['object']:
for atr in obj['primary-key']['attribute']:
if atr['name'] == 'inetnum':
v = atr['value']
cidrs.append(iprange_to_cidr(v)[0])
return cidrs
###
# Main
###
j = json.load(open('ripe-ips.json'))
get_cidrs(j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment