Stick to the continuous Python war cisconetwork.
#!/usr/bin/python from netmiko import connecthandlerfrom netmiko.ssh_exception Import netmikotimeoutexceptionimport timeimport sysimport getpassimport reimport stringioclass cisconetwork (): def __init__ (self , Username,password): self.username = username self.password = password def ciscodevice (self,iplist): self.device={' device_type ': ' Cisco_ios ', ' username ':self.username, ' Password ':self.password, ' IP ':iplist } print ('-' *100) print "[+]connect to network device... %s" % (iplist) self.connect = Connecthandler (**self.device) self.connect.enable () &nbsP;def gethostname (self): self.hostname = self.connect.find_prompt () self.hostname = self.hostname.replace ("# "," ") print self.hostname def interfaceinfo (Self,cmd): result = self.connect.send_command (CMD) for interface in result.split (' \ n '): if ' Up ' in interface: #print interface lines= Stringio.stringio (interface) data = lines.read () intername = ' '. Join (Re.findall (' ^eth.+\/\d '), Data)) loopback = ' ' Join (Re.findall (' loopback[0-9] ', data) interip = re.findall ( ' \. Join ([' \d{1,3} ']*4), data) if intername:         PRINT INTERNAME&NBSP, ': ', '. Join (InterIP) else: print loopback , ': ', '. Join (Interip) def show (Self,cmd): result = self.connect.send_ Command (CMD) lines = stringio.stringio (Result) data = lines.read () uptime = re.findall (' uptime.+ ', Data) id = re.findall (' \d{8} ', data) &nbsP; soft = re.findall (' l3_.+ ', data) print ' device uptime: ', '. Join (uptime) print ' device id: ', '. Join (ID) print ' soft version: ', '. Join (Soft) def close (self): if self.connect is not None: self.connect.disconnect () self.connect = none if __name__ == ' __main__ ':p rint "[+] this program is beging done ...] username = raw_input (' username: ') password = getpass.getpass () For iplist in open ("/opt/ Other/ip.txt "): try: switch = Cisconetwork (Username,password) switch. Ciscodevice (IPList) switch.gethostname () switch.interfaceinfo (' Show ip int&nbSp;brief ') switch.show (' show version ') switch.close () except (eoferror, netmikotimeoutexception): print (' Can not connect to device ')
Two things about Python and Cisco