def get_open_port(host="localhost"):
    """Get an open port on the machine.
    """
    temp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    temp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    temp_sock.bind((host, 0))
    port = temp_sock.getsockname()[1]
    temp_sock.close()
    del temp_sock
    return port
def get_open_port ( host = "localhost" ) : temp_sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) temp_sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) temp_sock . bind ( ( host , 0 ) ) port = temp_sock . getsockname ( ) [ 1 ] temp_sock . close ( ) del temp_sock return port
Get an open port on the machine.