import paramiko
import datetime
import time
f=open('./hostnames.txt','r') #准备好主机文件,一台主机占一行
hostnames=f.readlines()
#hostnames=['1.1.1.1','2.2.2.2','3.3.3.3','192.168.99.10','192.168.99.20'] #如果主机数量较少,可以以字符串的形式写入列表
for hostname in hostnames:
hostname=hostname.strip()
ssh_client=paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=hostname,username='python',password='123456') #连接登录网络设备
print('Sucessfully conneted to ',hostname)
cmd=ssh_client.invoke_shell()
cmd.send('display version\n')
time.sleep(1)
result=cmd.recv(66666)
result=result.decode('ascii') #将网络设备返回信息进行解码输出
print(result)
ssh_client.close()
标签:批量,Python,hostname,client,ssh,网络设备,hostnames,result
From: https://www.cnblogs.com/tang-learning/p/16846404.html