通过ciscolib模块中telnet-23端口批量配置交换机:
下面再讲通过paramiko模块下ssh安全批量配置再下图:
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import ciscolib
def main():
PASSWORD="12345678" #//测试环境
USERNAME="admin"
ENABLE_PWD="admin123"
for ip in open('sw3560.txt').readlines():
ip = ip.strip()
if USERNAME != "":
switch = ciscolib.Device(ip, PASSWORD, USERNAME, ENABLE_PWD)
else:
switch = ciscolib.Device(ip, PASSWORD, enable_password=ENABLE_PWD)
try:
switch.connect()
print("Logged into %s,Successful" % ip)
except ciscolib.AuthenticationError as e:
print("Couldn't connect to %s: %s" % (ip, e.value))
continue
except Exception as e:
print("Couldn't connect to %s: %s" % (ip, str(e)))