cmdshell.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:alfred-ec2 作者: SoMuchToGrok 项目源码 文件源码
def connect(self, num_retries=5):
        """
        Connect to an SSH server and authenticate with it.

        :type num_retries: int
        :param num_retries: The maximum number of connection attempts.
        """
        retry = 0
        while retry < num_retries:
            try:
                self._ssh_client.connect(self.server.hostname,
                                         username=self.uname,
                                         pkey=self._pkey,
                                         timeout=self._timeout)
                return
            except socket.error as xxx_todo_changeme:
                (value, message) = xxx_todo_changeme.args
                if value in (51, 61, 111):
                    print('SSH Connection refused, will retry in 5 seconds')
                    time.sleep(5)
                    retry += 1
                else:
                    raise
            except paramiko.BadHostKeyException:
                print("%s has an entry in ~/.ssh/known_hosts and it doesn't match" % self.server.hostname)
                print('Edit that file to remove the entry and then hit return to try again')
                raw_input('Hit Enter when ready')
                retry += 1
            except EOFError:
                print('Unexpected Error from SSH Connection, retry in 5 seconds')
                time.sleep(5)
                retry += 1
        print('Could not establish SSH connection')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号