Python Forum
telnet unexpected output printing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
telnet unexpected output printing
#1
Hi there, manual telnet is showing below output, however my program is not showing telnet output, please suggest changes.

Manual Telnet

Connected to 10.17.1.99.
Escape character is '^]'.
Login: admin
Password:

Host> dsl -c

Connect to DSL Console...
Press <Ctrl-\> or <Ctrl-Z> to return.

$get bridge port forwarding

Port Id : 3 vlan id : 3241
Mac Addr : E0:5F:B9:99:20:C1
Status : Learned

Port Id : 5 vlan id : 3604
Mac Addr : 0C:D2:B5:58:C4:4E
Status : Learned

Port Id : 6 vlan id : 3604
Mac Addr : 0C:D2:B5:61:EF:A4
Status : Learned

Port Id : 9 vlan id : 3604
Mac Addr : E4:6F:13:86:C7:D1
Status : Learned

Port Id : 10 vlan id : 3604
Mac Addr : 00:17:7C:75:93:E5
Status : Learned

Port Id : 14 vlan id : 3604
Mac Addr : 00:17:7C:7C:B1:D2
Status : Learned

Port Id : 19 vlan id : 3604
Mac Addr : 00:17:7C:7D:07:62
Status : Learned

Port Id : 24 vlan id : 3604
Mac Addr : 1C:5F:2B:55:59:A6
Status : Learned

Port Id : 193 vlan id : 1
Mac Addr : 00:1A:A2:26:72:2C
Status : Learned

Port Id : 193 vlan id : 3241
Mac Addr : 00:90:1A:A3:7C:DD
Status : Learned

Port Id : 193 vlan id : 3604
Mac Addr : 40:7C:7D:1F:89:73
Status : Learned
$
Host>

but telnet script is not showing output.

#!/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') + '\r')
            telnet.read_until('Password:', 3)
            telnet.write(password.encode('ascii') + '\r')
            print 'username password accepted'
            telnet.read_until('>')
            telnet.write('dsl -c' + '\r')
            telnet.read_until('$')
            print 'dsl prompt'
            telnet.write('get bridge port forwarding'+'\r')
            telnet.read_until('$')
            print 'Mac Details'
            telnet.write('\x1A' +'\r')
            print 'Control Z send'
            telnet.read_until('>')
            telnet.write('exit'+ '\r')
            output = telnet.read_all()
            print (output)
        except Exception as excp:
            print('Request Time out')
Script output

Connecting .....10.17.1.99
username password accepted
dsl prompt
Mac Details
Control Z send

and not showing output.
Reply
#2
please support.
Reply
#3
Why '\r' instead of '\n'? You write an empty string.? Why do you send a special symbol at all?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected output Starter 2 439 Nov-22-2023, 12:08 AM
Last Post: Starter
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 657 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Unexpected output while using random.randint with def terickson2367 1 469 Oct-24-2023, 05:56 AM
Last Post: buran
  Unexpected output from df.loc when indexing by label idratherbecoding 6 1,127 Apr-19-2023, 12:11 AM
Last Post: deanhystad
  Telnet command in Python 3.9 Dre83 0 1,931 Nov-11-2020, 11:42 AM
Last Post: Dre83
  unexpected output asyrafcc99 0 1,479 Oct-24-2020, 02:40 PM
Last Post: asyrafcc99
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,012 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner
  Sending command using telnet mradovan1208 1 3,886 Apr-24-2020, 07:09 PM
Last Post: Larz60+
  Printing output without print usage susmith552 1 1,627 Feb-07-2020, 07:52 PM
Last Post: Clunk_Head
  Unexpected output palladium 4 2,701 Jan-11-2020, 03:26 PM
Last Post: palladium

Forum Jump:

User Panel Messages

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