check for subnet conflicts
I'm writing a script that gets a /16 and breaks it down into different subnets (/24, 23, 27, etc). I realized that I may run into conflicting subnets, and I'm looking for a way to check that. I haven't found anything within ipcalc or netaddr that addresses this specifically. Thank youf or your help
def subnetting(self, cidrBlock, subnets): networks = subnets cidrblock = cidrBlock assigned_subnets =  ipnetwork = IPNetwork(cidrblock) subnet_list = ipnetwork.subnet(int(subnets)) for subnet in subnet_list: assigned_subnets.append(subnet) return assigned_subnets
To compare two subnets to see if they conflict, you need to apply the smallest mask to both to see if they are equal. If they are equal, then you have a conflict.
I will assume the 10.10.0.0/16 network. If you create 10.10.0.0/23 and 10.10.1.0/24, you compare them by applying the mask for /23 (255.255.254.0) to both 10.10.0.0 and 10.10.1.0.
10.10.0.0 AND 255.255.254.0 = 10.10.0.0 10.10.1.0 AND 255.255.254.0 = 10.10.0.0
They are equal, so they overlap and conflict.
Try with ipconflict.
ipconflict 10.0.1.0/24 10.0.1.0/22
conflict found: 10.0.1.0/24 <-> 10.0.1.0/22