from iptools import IpRange
def search_cidr(ip, cidrs):
for cidr in cidrs:
if ip in IpRange(cidr):
return cidr
return False
if __name__ == '__main__':
cidrs = ['10.0.0.0/30', '10.0.0.5/32']
your_ip = '10.0.0.2'
find = search_cidr(your_ip, cidrs)
if find:
print('Found:', find)