device.py 文件源码

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

项目:needle 作者: mwrlabs 项目源码 文件源码
def _connect_ssh(self):
        """Open a new SSH connection using Paramiko."""
        try:
            self.printer.verbose("[SSH] Connecting ({}:{})...".format(self._ip, self._port))
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect(self._ip, port=self._port, username=self._username, password=self._password,
                        allow_agent=self._pub_key_auth, look_for_keys=self._pub_key_auth)
            self.printer.notify("[SSH] Connected ({}:{})".format(self._ip, self._port))
            return ssh
        except paramiko.AuthenticationException as e:
            raise Exception('Authentication failed when connecting to %s. %s: %s' % (self._ip, type(e).__name__, e.message))
        except paramiko.SSHException as e:
            raise Exception('Connection dropped. Please check your connection with the device, '
                            'and reload the module. %s: %s' % (type(e).__name__, e.message))
        except Exception as e:
            raise Exception('Could not open a connection to %s. %s - %s' % (self._ip, type(e).__name__, e.message))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号