Exemplo n.º 1
0
 def open (self):
     client = SSH_Client_Transport()
     transport = coro_socket_transport (self.ip, port=self.port, hostname=self.hostname)
     client.connect (transport)
     auth_method = Userauth (client, self.username)
     service = Connection_Service (client)
     client.authenticate (auth_method, service.name)
     channel = Interactive_Session_Client (service)
     channel.open()
     return channel
Exemplo n.º 2
0
 def open(self):
     client = SSH_Client_Transport()
     transport = coro_socket_transport(self.ip,
                                       port=self.port,
                                       hostname=self.hostname)
     client.connect(transport)
     auth_method = Userauth(client, self.username)
     service = Connection_Service(client)
     client.authenticate(auth_method, service.name)
     channel = Interactive_Session_Client(service)
     channel.open()
     return channel
Exemplo n.º 3
0
    def connect(self,
                username,
                remote_address,
                remote_port=22,
                password=None,
                command=None,
                debug_level=coro.ssh.util.debug.WARNING):
        """connect(self, username, remote_address, remote_port=22, password=None,
                   command=None, debug_level=coro.ssh.util.debug.WARNING) -> None
        The opens a connection to the remote side and authenticates.

        <username> - The remote username to log into.
        <remote_address> - The remote address to connect to.
        <remote_port> - The remote port to connect to.
        <password> - The password to use when connecting to the remote side.
                     If None, and there are no authorized_keys configured,
                     then it will ask for the password on stdout/stdin.
                     If DISABLE_PASSWORD, will disable password auth.
        <command> - The command to run on the remote side.
                    If no command is given, then it will open a pty and shell.
        <debug_level> - Level a debuging to print to stderr.
        """

        self.client = coro.ssh.transport.client.SSH_Client_Transport()
        if inet_utils.is_ip(remote_address):
            remote_ip = remote_address
            hostname = None
        else:
            dns_query_result = dnsqr.query(remote_address, 'A')
            remote_ip = dns_query_result[0][-1]
            hostname = remote_address
        coro_socket_transport = coro.ssh.l4_transport.coro_socket_transport
        self.transport = coro_socket_transport.coro_socket_transport(
            remote_ip, remote_port, hostname=hostname)
        self.client.connect(self.transport)
        self.client.debug.level = debug_level
        self.service = coro.ssh.connection.connect.Connection_Service(
            self.client)
        self._authenticate(username, password)
        self.channel = coro.ssh.connection.interactive_session.Interactive_Session_Client(
            self.service)
        self.channel.open()
        if command is not None:
            self.channel.exec_command(command)
        else:
            self.channel.open_pty()
            self.channel.open_shell()
    def connect(
        self,
        username,
        remote_address,
        remote_port=22,
        password=None,
        command=None,
        debug_level=coro.ssh.util.debug.WARNING,
    ):
        """connect(self, username, remote_address, remote_port=22, password=None,
                   command=None, debug_level=coro.ssh.util.debug.WARNING) -> None
        The opens a connection to the remote side and authenticates.

        <username> - The remote username to log into.
        <remote_address> - The remote address to connect to.
        <remote_port> - The remote port to connect to.
        <password> - The password to use when connecting to the remote side.
                     If None, and there are no authorized_keys configured,
                     then it will ask for the password on stdout/stdin.
                     If DISABLE_PASSWORD, will disable password auth.
        <command> - The command to run on the remote side.
                    If no command is given, then it will open a pty and shell.
        <debug_level> - Level a debuging to print to stderr.
        """

        self.client = coro.ssh.transport.client.SSH_Client_Transport()
        if inet_utils.is_ip(remote_address):
            remote_ip = remote_address
            hostname = None
        else:
            dns_query_result = dnsqr.query(remote_address, "A")
            remote_ip = dns_query_result[0][-1]
            hostname = remote_address
        coro_socket_transport = coro.ssh.l4_transport.coro_socket_transport
        self.transport = coro_socket_transport.coro_socket_transport(remote_ip, remote_port, hostname=hostname)
        self.client.connect(self.transport)
        self.client.debug.level = debug_level
        self.service = coro.ssh.connection.connect.Connection_Service(self.client)
        self._authenticate(username, password)
        self.channel = coro.ssh.connection.interactive_session.Interactive_Session_Client(self.service)
        self.channel.open()
        if command is not None:
            self.channel.exec_command(command)
        else:
            self.channel.open_pty()
            self.channel.open_shell()