import socket


def get_local_ip(target=None):
    """
    Get the "public" IP address without sending any packets.

    :param target: Since the host might have different interfaces,
    we want to know the IP address that will be used to connect to "target",
    not just the "default gateway" IP address.

    :return: The IP address.
    """
    connect_target = '4.4.4.2' if target is None else target
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        #   UDP is connection-less, no packets are sent to 4.4.4.2
        #   I use port 80, but could use any port
        sock.connect((connect_target, 80))
        local_address = sock.getsockname()[0]
    except Exception:
        return None
    else:
        return local_address