def is_cidr_in_cidr(small_cidr, big_cidr):
"""
Return True if the small CIDR is contained in the big CIDR.
"""
# The default route (0.0.0.0/0) is handled differently, since every route
# would always be contained in there. Instead, only a small CIDR of
# "0.0.0.0/0" can match against it. Other small CIDRs will always result in
# 'False' (not contained).
if small_cidr == "0.0.0.0/0":
return big_cidr == "0.0.0.0/0"
else:
if big_cidr == "0.0.0.0/0":
return False
s = ipaddress.IPv4Network(unicode(small_cidr))
b = ipaddress.IPv4Network(unicode(big_cidr))
return s.subnet_of(b)
评论列表
文章目录