Python Forum
telnet unexpected output printing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
telnet unexpected output printing
#4
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.

#!/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.
Reply


Messages In This Thread
telnet unexpected output printing - by anna - Jan-12-2018, 11:11 AM
RE: telnet unexpected output printing - by anna - Jan-16-2018, 05:01 PM
RE: telnet unexpected output printing - by wavic - Jan-16-2018, 05:52 PM
RE: telnet unexpected output printing - by anna - Jan-17-2018, 01:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected output when trying to attach files in a mail application PythonU2Novel 0 426 May-17-2024, 02:59 AM
Last Post: PythonU2Novel
  Unexpected output Starter 2 625 Nov-22-2023, 12:08 AM
Last Post: Starter
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 930 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Unexpected output while using random.randint with def terickson2367 1 632 Oct-24-2023, 05:56 AM
Last Post: buran
  Unexpected output from df.loc when indexing by label idratherbecoding 6 1,408 Apr-19-2023, 12:11 AM
Last Post: deanhystad
  Telnet command in Python 3.9 Dre83 0 2,057 Nov-11-2020, 11:42 AM
Last Post: Dre83
  unexpected output asyrafcc99 0 1,563 Oct-24-2020, 02:40 PM
Last Post: asyrafcc99
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,147 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner
  Sending command using telnet mradovan1208 1 4,168 Apr-24-2020, 07:09 PM
Last Post: Larz60+
  Printing output without print usage susmith552 1 1,765 Feb-07-2020, 07:52 PM
Last Post: Clunk_Head

Forum Jump:

User Panel Messages

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