码迷,mamicode.com
首页 > 编程语言 > 详细

python 链接交换机并执行相关命令

时间:2018-10-23 16:26:50      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:result   pen   character   交换机   命令   key   shel   []   lse   

原文地址 https://blog.csdn.net/u010897775/article/details/80311786?utm_source=blogxgwz0

# encoding=utf-8
import paramiko
import time
client = paramiko.SSHClient()
client.load_system_host_keys()
 
# connect to client
client.connect(192.168.254.141,22,test,test,allow_agent=False,look_for_keys=False)
 
# get shell
ssh_shell = client.invoke_shell()
# ready when line endswith ‘>‘ or other character
while True:
    line = ssh_shell.recv(1024)
    #print line
    if line and line.endswith(>):
        break;
 
# send command
ssh_shell.sendall( ping 192.168.254.142 + \n)
 
# get result lines
lines = []
while True:
    line = ssh_shell.recv(1024)
    if line and line.endswith(>):
        break;
    lines.append(line)
result = ‘‘.join(lines)
 
# print result
print result

 

python 链接交换机并执行相关命令

标签:result   pen   character   交换机   命令   key   shel   []   lse   

原文地址:https://www.cnblogs.com/liuxm2017/p/9837157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!