Python与Cisco 的事儿
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python与Cisco 的事儿相关的知识,希望对你有一定的参考价值。
今天花了一个小时研究了Python的另外一个操作网络设备的插件Netmiko,这玩意还是满好玩的,只是我还是整不明白如何多线程,还是得努力努力。
#!/usr/bin/python from netmiko import ConnectHandler import time class CiscoNetwork: def __init__(self): pass def CiscoDevice(self,iplist): device={'device_type':'cisco_ios', 'ip':iplist, 'username':'admin', 'password': 'Password.123' } print "connect to network device... %s" %(iplist) self.connect = ConnectHandler(**device) self.connect.enable() time.sleep(0.5) def gethostname(self): #用来获取设备的hostname self.hostname = self.connect.find_prompt() self.hostname = self.hostname.replace("#","") print self.hostname def show(self,cmd): #执行命令 self.output = self.connect.send_command(cmd) print self.output def close(self): self.connect.close() if __name__ == '__main__': print "[+] This Program is beging done......." for iplist in open("/opt/other/ip.txt"): switch = CiscoNetwork() switch.CiscoDevice(iplist) switch.gethostname() switch.show('show ip int brief')
以上是关于Python与Cisco 的事儿的主要内容,如果未能解决你的问题,请参考以下文章