PHP前端开发

使用python管理Cisco设备

百变鹏仔 3小时前 #Python
文章标签 设备

发现一个老外使用python写的管理cisco设备的小框架tratto,可以用来批量执行命令。

下载后主要有3个文件:

Systems.py 定义了一些不同设备的操作系统及其常见命令。

Connectivity.py 是主要实现功能的代码,其实主要就是使用了python的pexpect模块。

Driver.py是一个示例文件。

立即学习“Python免费学习笔记(深入)”;

[root@safe tratto-master]# cat driver.py

#!/usr/bin/env pythonimport Connectivityimport Systems#telnet to a cisco switchm = Systems.OperatingSystems['IOS']s = Connectivity.Session("192.168.1.1",23,"telnet",m)s.login("yourusername", "yourpassword")# if your need to issue an "enable" commands.escalateprivileges('yourenablepassword')s.sendcommand("show clock")s.sendcommand("show run")s.logout()