bundlewrap/libs/firewall.py

37 lines
891 B
Python
Raw Normal View History

from os.path import abspath, dirname, join
from ipaddress import ip_network, IPv4Network
REPO_PATH = dirname(dirname(abspath(__file__)))
def generate_ip_list_from_routes(filename):
# generated using:
# whois -i origin as8881 | awk '/^route/ {print $2}' > configs/as8881.txt
with open(join(REPO_PATH, 'configs', f'{filename}.txt')) as f:
networks = f.read().splitlines()
result = {
'ipv4': set(),
'ipv6': set(),
}
for line in networks:
line = line.strip()
if not line or line.startswith('#'):
continue
ip = ip_network(line)
if isinstance(ip, IPv4Network):
result['ipv4'].add(ip)
else:
result['ipv6'].add(ip)
return result
named_networks = {
'versatel': generate_ip_list_from_routes('as8881'),
2021-12-14 15:09:31 +00:00
'telekom': generate_ip_list_from_routes('as3320'),
}