H3C交换机python命令下发脚本
2021-07-14 01:06
标签:共享 war 网工 nes adl err 一个 研究 inter 方向比较简单,通过python的open方法读取iplist.txt里面的IP地址,这些ip就是所需要下发命令的交换机ip地址。然后读取cmdlist里面需要下发的哪些命令。通过python的netmiko ssh连接到交换机自动下发 h3c_check.py coding:utf-8 import time #读取iplist.txt 文档里面的ip地址 cmdlist = open(‘cmdlist.txt‘,‘r‘,encoding = ‘ascii‘) #遍历ip_addr这个列表里面的ip进行连接 iplist.txt 192.168.11.112 cmdlist.txt display vlan H3C交换机python命令下发脚本 标签:共享 war 网工 nes adl err 一个 研究 inter 原文地址:http://blog.51cto.com/1339643/2164819
from netmiko import *
import sys
import os
import getpass
iplist = open(‘iplist.txt‘,‘r‘,encoding = ‘ascii‘)
ip_addr = iplist.readlines()
iplist.close()
cmd_line = cmdlist.readlines()
cmdlist.close()
for ip in iter(ip_addr):
print(ip)
try:
S5130 = {
‘device_type‘:‘hp_comware‘,
‘ip‘:ip,
‘username‘:‘h3c‘,
‘password‘:‘h3c‘,
} net_connect = ConnectHandler(**S5130)
for cmd in iter(cmd_line):
cmd_result = net_connect.send_command(cmd)
print(‘-----------------------------------------------------------------‘)
print(cmd)
print(cmd_result)
print(‘-----------------------------------------------------------------‘)
print(‘‘)
net_connect.disconnect()
except (EOFError, NetMikoTimeoutException):
print(‘Can not connect to Device‘)
except (EOFError, NetMikoAuthenticationException):
print(‘username/password wrong!‘)
192.168.11.110
display version
display ip inter brief
文章标题:H3C交换机python命令下发脚本
文章链接:http://soscw.com/index.php/essay/104880.html