You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
931 B
Python

import ipaddress
def zone_is_subset(re2o_reverse_zone, network):
"""Check if all the subnets are inside another network
Examples
--------
An Example to check if the function works as intended
>>> net1 = ipaddress.IPv4Network("10.11.0.0/16")
>>> cidrs = ['10.11.1.0/24', '10.11.2.0/23', '10.11.4.0/22']
>>> zone = {'cidrs': cidrs}
>>> zone_is_subset(zone, net1)
True
"""
if network.version == 4:
return all(ipaddress.ip_network(n).subnet_of(network) for n in
re2o_reverse_zone["cidrs"])
elif network.version == 6:
if re2o_reverse_zone["prefix_v6"]:
ipv6_prefix = re2o_reverse_zone["prefix_v6"]
ipv6_prefix_length = re2o_reverse_zone["prefix_v6_length"]
net6 = ipaddress.ip_network(f"{ipv6_prefix}/{ipv6_prefix_length}")
return net6.subnet_of(network)
else:
return False