Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with print format
#8
killerrex

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
Reply


Messages In This Thread
problem with print format - by anna - May-15-2018, 05:52 PM
RE: problem with print format - by nilamo - May-15-2018, 06:09 PM
RE: problem with print format - by anna - May-15-2018, 06:39 PM
RE: problem with print format - by killerrex - May-15-2018, 07:07 PM
RE: problem with print format - by anna - May-15-2018, 07:43 PM
RE: problem with print format - by killerrex - May-15-2018, 11:12 PM
RE: problem with print format - by anna - May-16-2018, 08:01 AM
RE: problem with print format - by anna - May-16-2018, 11:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with print command in super() akbarza 5 666 Feb-01-2024, 12:25 PM
Last Post: deanhystad
  problem with spliting line in print akbarza 3 433 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  problem with print lists MarekGwozdz 4 747 Dec-15-2023, 09:13 AM
Last Post: Pedroski55
  Problem with print variable in print.cell (fpdf) muconi 0 690 Dec-25-2022, 02:24 PM
Last Post: muconi
  Print first day of the week as string in date format MyerzzD 2 2,061 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 3,035 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  C to Python code conversion print problem anakk1n 1 2,213 May-22-2020, 04:15 PM
Last Post: deanhystad
  Highscore problem, need to print top 5 Camiosobro123 5 4,958 Jan-29-2020, 03:31 PM
Last Post: ThiefOfTime
  Parquet format conversion problem Bilhardas 1 1,675 Nov-19-2019, 11:06 AM
Last Post: baquerik
  misunderstanding of format in print function Harvey 2 2,206 Oct-29-2019, 12:44 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020