import socket


def is_ipv4(ip: str) -> bool:
    """
    判断ip是否为可连接的ipv4

    Determine whether the IP is a connectable IPv4
    :param ip: like 8.8.8.8 etc.
    :return: bool
    """
    try:
        socket.inet_pton(socket.AF_INET, ip)
    except AttributeError:  # no inet_pton here, sorry
        try:
            socket.inet_aton(ip)
        except socket.error:
            return False
        return ip.count('.') == 3
    except socket.error:  # not a valid ip
        return False
    return True