def run(self): port = Endpoint.find_unused_port(1000, 10000) if port is None: self.error_signal.emit( "No port available in order to create SSH tunnel") return try: self._ssh_client.transport = paramiko.Transport(( self._ssh_client.host(), self._ssh_client.ssh_port(), )) self._ssh_client.transport.set_keepalive(30) with open(self._ssh_client.ssh_key()) as f: self._ssh_client.transport.connect( username=self._ssh_client.user(), pkey=paramiko.RSAKey.from_private_key(f)) endpoint = Endpoint(("127.0.0.1", port), ("127.0.0.1", self._ssh_client._http_port), self._ssh_client.transport) endpoint.enable() self._ssh_client._endpoints[port] = endpoint except (paramiko.ssh_exception.SSHException, OSError) as e: self.error_signal.emit(str(e)) return self._ssh_client._http_port = port self.connected_signal.emit()
def getTunnel(self, port): """ Get a tunnel to the remote port. For HTTP standard client it's the same port. For SSH it will be different :param port: Remote port :returns: Tuple host, port to connect """ new_port = Endpoint.find_unused_port(1000, 10000) endpoint = Endpoint(("127.0.0.1", new_port), ("127.0.0.1", port), self.transport) endpoint.enable() self._endpoints[new_port] = endpoint return ("127.0.0.1", new_port)
def run(self): port = Endpoint.find_unused_port(1000, 10000) if port is None: self.error_signal.emit("No port available in order to create SSH tunnel") return try: self._ssh_client.transport = paramiko.Transport((self._ssh_client.host(), self._ssh_client.ssh_port(), )) self._ssh_client.transport.set_keepalive(30) with open(self._ssh_client.ssh_key()) as f: self._ssh_client.transport.connect(username=self._ssh_client.user(), pkey=paramiko.RSAKey.from_private_key(f)) endpoint = Endpoint(("127.0.0.1", port), ("127.0.0.1", self._ssh_client._http_port), self._ssh_client.transport) endpoint.enable() self._ssh_client._endpoints[port] = endpoint except (paramiko.ssh_exception.SSHException, OSError) as e: self.error_signal.emit(str(e)) return self._ssh_client._http_port = port self.connected_signal.emit()