libs.tools.resolve_identifier: add support for named networks
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good
This commit is contained in:
parent
969b45d9f7
commit
1742f51778
3 changed files with 707 additions and 8 deletions
35
libs/firewall.py
Normal file
35
libs/firewall.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
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'),
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue