如何使用python的paramiko模块实现对H3C交换机的巡检
问题描述:
我使用python中的paramiko模块对H3C交换机进行设备巡检时,发现巡检命命令输出结果都是空的,有谁有能运行针对H3C交换机的python巡检脚本吗,要求用paramiko实现。
组网及组网描述:
可以自己百度写下,或者标杆进行巡检
6小时前回答暂无
stdin, stdout, stderr = ssh.exec_command(command)
# print(stdout.read().decode('utf-8').replace('\r', ''))
cOntent= stdout.read().decode('utf-8').replace('\r', '')
读取数据时候改一下uft-8试试
我测试过程中如果有出现某些v5设备时,好像会出现display cu中间数据全空,这个我也没找到对应解决方法
暂无
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.conneect(ip, port, username, password)
# ip :str
# port: int default = 22
# username: str
# password: str
terminal = client.invoke_shell() # 用这种方式可以用一个ssh会话发送多个命令
# 如果是client.exec_command()的话只能发送一次命令,ssh通道就断了
terminal.send("screen-length disable \r".encode("utf-8")) # 这条命令是为了用的命令的回显太多,单次回显全部显示,\r是回车,输入命令必须要,编码成utf-8,不过华三设备缺省是gb系列的
# 命令从文件读取然后for循环发送就行了
暂无
你正在内容来源:知了社区,如何使用python的paramiko模块实现对H3C交换机的巡检