欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

使用Paramiko穿越堡垒机连接服务器的方法

最编程 2024-02-10 08:45:29
...

paramiko 通过堡垒机连接服务器


#!/usr/bin/env python
# encoding: utf-8

import paramiko
import time
def get_inst_log(ip,command):
    ssh=paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect('test.lili.test','2222','xxxxx','123',timeout=10)
    invoke=ssh.invoke_shell()
    invoke.send(ip+'\r')
    #time.sleep(2)
    invoke.send('5\r')
    #invoke.send('ll\r')
    time.sleep(2)
    invoke.send(command+'\r')
    time.sleep(2)
    a=invoke.recv(99999).decode()
    print(a)
    ssh.close()

if __name__=="__main__":
    ip='127.0.0.1'
    command=r'tail -f /AppHome/Logs/zf/all.8080.log'
    get_inst_log(ip,command)


















©著作权归作者所有,转载或内容合作请联系作者

推荐阅读