May-16-2018, 11:28 AM
killerrex
its working now, now going for Multiple threading, as device count is high
its working now, now going for Multiple threading, as device count is high
import telnetlib import re HOST = "10.10.1.10" user = "test" password = "test@123" telnet = telnetlib.Telnet(HOST) #telnet.set_debuglevel(2) telnet.read_until("Username: ",3) telnet.write(user + "\n") if password: telnet.read_until("Password:",3) telnet.write(password + "\n") telnet.write("term len 0 \n") telnet.read_until(">") telnet.write("show ver \n") telnet.write("Show ntp status \n") telnet.write("Show ntp association\n") telnet.write("show snmp \n") telnet.read_until(">",10) telnet.write("exit\n") Veroutput = telnet.read_all() for line in Veroutput.split('\n'): if 'Version' in line: Version = (line.split(',')[1]).split(' ')[2] elif 'image' in line: Raw_Image = line.split(':')[1][:-1] Image = Raw_Image[:-1] elif 'Processor board ID' in line: ProcessorID = (line.split(' ')[3]).split('\r')[0] elif 'Model number' in line: Model = (line.split(':')[1]).split('\r')[0] elif 'MAC Address' in line: MACAddress = (line.split(' ')[4]).split('\r')[0] elif 'System serial number' in line: SystemSerialNumber = (line.split(':')[1]).split('\r')[0] elif 'Clock' in line: NTPStatus = line.split(',')[0] NTPsyncStatus = NTPStatus.split(' ')[2] elif '*~' in line: NTPAssociationDelay = re.sub('\s{2,}', ' ', line).split(' ')[5] elif 'logging:' in line: SNMPlogging = line.split(':')[1].strip() elif 'agent' in line: SNMPAgentStatus = (line.split(' ')[2]).split('\r')[0] # Now that all the lines are read, report the result print('{} {} {} {} {} {} {} {} {} {} {}'.format( HOST, Version, Image, ProcessorID, MACAddress, Model, SystemSerialNumber, NTPsyncStatus, NTPAssociationDelay, SNMPlogging, SNMPAgentStatus))
Output:10.10.1.10 12.1(22)EA12 c2950-i6q4l2-mz.121-22.EA12.bin FOC0835X50K 00:12:00:DD:AD:40 WS-C2950G-24-EI FOC0835X50K synchronized 377 enabled enabled