Created
February 18, 2014 00:39
-
-
Save fritz0705/9062266 to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
import netaddr | |
import lglass.bird | |
import lglass.route | |
import lglass.database.file | |
with open("routes.bird") as fh: | |
routes = lglass.route.RoutingTable(lglass.bird.parse_routes(fh)) | |
db = lglass.database.file.FileDatabase("/home/fritz/dn42/net.dn42.registry/data") | |
dn42_native = netaddr.IPNetwork("172.22.0.0/15") | |
db_nets = netaddr.IPSet() | |
route_nets = netaddr.IPSet() | |
for type, primary_key in db.list(): | |
if type == "inetnum": | |
addr = netaddr.IPNetwork(primary_key) | |
if addr not in dn42_native: | |
continue | |
obj = db.get(type, primary_key) | |
if "BLK" in obj.getfirst("netname", ""): | |
continue | |
db_nets.add(addr) | |
for route in routes: | |
if route.prefix not in dn42_native: | |
continue | |
route_nets.add(route.prefix) | |
all_nets = netaddr.IPSet() | |
all_nets.add(dn42_native) | |
announced_nets = route_nets | |
registered_nets = db_nets | |
unused_nets = all_nets - announced_nets | |
unregistered_nets = all_nets - registered_nets | |
free_nets = unused_nets.intersection(unregistered_nets) | |
for net in free_nets.iter_cidrs(): | |
print(net) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment