ssh.py 文件源码

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

项目:watchmen 作者: lycclsltt 项目源码 文件源码
def run(self, cmd):
        ssh_newkey = 'Are you sure you want to continue connecting'
        child = pexpect.spawn('ssh -l %s -p %s %s %s'%(self._user, self._port, self._host, cmd))
        i = child.expect([pexpect.TIMEOUT, ssh_newkey, 'password: '])
        if i == 0: #timeout
            raise Exception('ssh timeout')
        if i == 1: #SSH does not have the public key. Just accept it.
            child.sendline('yes')
            child.expect('password: ')
            i = child.expect([pexpect.TIMEOUT, 'password: '])
            if i == 0: #timeout
                raise Exception('ssh timeout')
        child.sendline(self._pwd)
        child.expect(pexpect.EOF)
        return child.before
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号