-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexagen.py
More file actions
47 lines (34 loc) · 880 Bytes
/
exagen.py
File metadata and controls
47 lines (34 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# ExaBGP route generator
# Jonathan P. Voss
# 4/1/2022
#
from ipaddress import ip_network
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:
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()