It took me one hours to study the other Python plug-in for the network device Netmiko, which is still full of fun, but I still do not understand how to multi-threading, or have to work hard.
#!/usr/bin/pythonfrom netmiko import connecthandlerimport timeclass 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 &nbsP; 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 ')
The Python and Cisco thing