Feb-21-2018, 07:55 AM
Thanks,
I have made some changes in code, sending output to list and taking bport from list as parameter to next command, however I am missing something.
print ('It took {:.2f} seconds'.format(exec_time)) #change exec_time to whatever name you useis to check execution time, and will not be there in final code. Just to calculate time to decide the number threads required to complete 1000+ devices.
I have made some changes in code, sending output to list and taking bport from list as parameter to next command, however I am missing something.
def mac2norm(mac): mac = mac.split(' ') return '{:0>2}:{:0>2}:{:0>2}:{:0>2}:{:0>2}'.format(*mac).upper() #header = ('mac address', 'bport', 'vlan') #print('{:^17} {:^5} {:^4}'.format(*header)) #print('='*33) MyList = [] for line in output.decode('utf-8').split('\n')[4:]: line = line.split('|') if len(line) == 8: mac, bport, vlan = map(lambda x: x.strip(), line[:3]) mac_address = mac2norm(mac) #print('{} {} {} {}'.format(host,mac_address, bport, vlan)) MyList = host,mac_address, bport, vlan #print('{} {} {} {}'.format(*MyList)) dslam_bport = (MyList[3]) print(dslam_bport) session.write("bportr ".encode('ascii') + dslam_bport +b"\r") portoutput = session.read_until("MCR64A >".encode('ascii'), timeout ) for line in portoutput.decode('utf-8').split('\n'): if 'Port:' in line: raw_port = line.split(':') port = line[1] MyList.append(port) print('{} {} {} {}'.format(host,mac_address, bport, vlan, port))facing below error
Error:Starting Client...
Connecting...
Sending Commands...
Reading...
3612
Traceback (most recent call last):
File "ecicollector-1.py", line 52, in <module>
session.write("bportr ".encode('ascii') + dslam_bport +b"\r")
File "/usr/lib64/python2.7/telnetlib.py", line 279, in write
if IAC in buffer:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)