I assume that you really want both CIDRs to represent ranges, although in your example 192.168.2.0/32 is only one address. Also note that in 192.168.2.0/14,.2. does not make sense, since the 14-bit prefix does not reach the third octet.
In any case, there are several ways to do this. You may have noticed that for overlapping they should always be a subset of the other:
def cidrsOverlap(cidr0, cidr1): return cidr0 in cidr1 or cidr1 in cidr0
Or you may have noticed that for overlapping ranges, the lower address of the first range must be less than or equal to the highest address of the second range and vice versa. Thus:
def cidrsOverlap(cidr0, cidr1): return cidr0.first <= cidr1.last and cidr1.first <= cidr0.last print cidrsOverlap(IPNetwork('192.168.2.0/24'), IPNetwork('192.168.3.0/24'))
rob mayoff
source share