Jan-17-2018, 01:16 PM
there are two prompts
1) >
2) $
MAC details is getting on second prompt,to come out of $ prompt need to send Ctrl+z, so sending special character.
1) >
2) $
MAC details is getting on second prompt,to come out of $ prompt need to send Ctrl+z, so sending special character.
#!/usr/bin/python import paramiko import xlwt import sys import os import xlrd import unidecode import telnetlib import time import re from time import sleep user = 'admin' password = '1234' with open('ut.txt','r') as ipfile: for sr_no, line in enumerate(ipfile, start=1): host = line.strip() try: print 'Connecting .....'+str(host) telnet = telnetlib.Telnet(host, 23, 2) telnet.read_until('Login:', 3) telnet.write(user.encode('ascii') + '\n') telnet.read_until('Password:', 3) telnet.write(password.encode('ascii') + '\n') print 'username password accepted' telnet.read_until('>') print 'Outer Prompt' telnet.write('dsl -c' + '\n') print 'dsl -c' telnet.read_until('$') print 'dsl prompt' telnet.write('get bridge port forwarding'+'\n') sleep(1) #telnet.read_until('$') print 'Mac Details' telnet.write('\x1A') print 'Control Z send' telnet.read_until('>') telnet.write('exit'+ '\n') output = telnet.read_all() print (output) except Exception as excp: print('Request Time out')tried with '\n' instead of '\r' but same result.