Last active
April 1, 2022 20:18
-
-
Save jvoss/9e2c8992590fbd4486a0776e17a6209e to your computer and use it in GitHub Desktop.
ExaBGP route generator
This file contains 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
#!/usr/bin/env python | |
# ExaBGP route generator | |
# Jonathan P. Voss | |
# 4/1/2022 | |
# | |
from ipaddress import ip_network | |
import re | |
import sys | |
import time | |
nexthop = sys.argv[1] | |
max_routes = sys.argv[2] | |
def announce(prefix, nexthop): | |
sys.stdout.write('announce route %s next-hop %s\n' % (prefix.with_prefixlen, nexthop)) | |
sys.stdout.flush() | |
time.sleep(0.0005) | |
def build_generators(): | |
blocks = [] | |
for x in range(1, 255): | |
blocks.append(ip_network('%d.0.0.0/8' % x).subnets(new_prefix=24)) | |
return blocks | |
def main(): | |
block = list(build_generators()) | |
supernet = list(block.pop(0)) | |
for x in range(0, int(max_routes)): | |
try: | |
# announce(supernet.pop(0), nexthop) | |
net = supernet.pop(0) | |
except IndexError: | |
supernet = list(block.pop(0)) | |
net = supernet.pop(0) | |
announce(net, nexthop) | |
# Prevent looping updates | |
while True: | |
time.sleep(1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment