def is_valid_ip_address(address, family=socket.AF_INET):
    is_windows = platform.system() == 'Windows'

    if is_windows and family == socket.AF_INET6:
        raise ValueError('Checking IPv6 addresses is not supported on Windows')

    try:
        if is_windows:
            socket.inet_aton(address)
        else:
            socket.inet_pton(family, address)
    except socket.error:
        return False

    return True
Check if the provided address is valid IPv4 or IPv6 address.
dataset/ETHPy150Open apache/libcloud/libcloud/utils/networking.py/is_valid_ip_address