Add a subnet checker
This commit is contained in:
parent
d084bdefd0
commit
0a01989fc6
1 changed files with 17 additions and 0 deletions
17
subnet.py
Normal file
17
subnet.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
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
|
||||
"""
|
||||
return all(ipaddress.ip_network(n).subnet_of(network) for n in
|
||||
zone["cidrs"])
|
Loading…
Reference in a new issue