import ipaddress


def is_valid_ip(v):
    """Check if is a valid IP address

    :param str v: A string value
    :return: IP address version if valid, else 0
    :rtype: int
    """
    try:
        ip = ipaddress.ip_address(v)
    except ValueError:
        version = 0

    else:
        version = ip.version

    return version