def ip_to_cidr(ip):
    """Convert IP address to CIDR.

    Example: '255.255.255.0' will return 24
    """
    # Thanks to @Atticfire
    # See https://github.com/nicolargo/glances/issues/1417#issuecomment-469894399
    if ip is None:
        return 0
    return sum(bin(int(x)).count('1') for x in ip.split('.'))