def validate_ip_cidr(ip, allow_no_mask=False):
     if not ip:
         return False
     ip = ip.strip()
     m = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(/(\d{1,2})$|$)", ip)
     mask = m.group(6)
     if m:
         a1, a2, a3, a4 = int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4))
         if a1<256 and a2<256 and a3<256 and a4<256:
             ip_canon = "{}.{}.{}.{}".format(a1, a2, a3, a4)
             if mask and int(mask) >= 0 and int(mask) <= 32:
                 return "{}/{}".format(ip_canon, mask)
             if allow_no_mask and not mask:
                 return ip_canon
     return False
Check if the IP address range is correct in CIDR format: xxx.xxx.xxx.xxx/nn
dataset/ETHPy150Open securitykiss-com/rfw/rfw/iputil.py/validate_ip_cidr