def get_port(socket): """Return the port to which a socket is bound.""" addr, port = socket.getsockname() return port