import ipaddress


def _cidr(string):
    """ Convert netmask to prefix length in IP address string """
    try:
        return ipaddress.ip_interface(string.replace(' ', '/')).with_prefixlen
    except ValueError:
        return string