import socket


def tcp_port_reachable(addr, port, timeout=5):
    """
    Return 'True' if we could establish a TCP connection with the given
    addr:port tuple and 'False' otherwise.

    Use the optional third argument to determine the timeout for the connect()
    call.
    """

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(timeout)
    try:
        s.connect((addr, port))
        s.shutdown(socket.SHUT_RDWR)
        return True
    except:
        return False