Created
January 28, 2016 12:27
-
-
Save homelinen/92d8f46019d4e321a815 to your computer and use it in GitHub Desktop.
Horrible quick script to scrape RIPE Json files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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