ssh – Does anyone know why do not write the word “user” in when the “Username:” is show? it jumps over “show clock” any idea what might be wrong?


Telnet(localhost,61823): recv b’xffxfbx01xffxfbx03xffxfdx18xffxfdx1f’
Telnet(localhost,61823): IAC WILL 1
Telnet(localhost,61823): IAC WILL 3
Telnet(localhost,61823): IAC DO 24
Telnet(localhost,61823): IAC DO 31
Telnet(localhost,61823): recv b’rn************************************************’
Telnet(localhost,61823): recv b’*********************************rnrn ‘
Telnet(localhost,61823): recv b’ IMPORTANT NOTICErn Access t’
Telnet(localhost,61823): recv b’o this network device is restricted to authorized ‘
Telnet(localhost,61823): recv b’personnel only.rn This system ‘
Telnet(localhost,61823): recv b’is permanently monitored.rn Any ‘
Telnet(localhost,61823): recv b’unauthorized access will be prosecuted.rnrn*******’
Telnet(localhost,61823): recv b’**************************************************’
Telnet(localhost,61823): recv b’************************rnrnUser Access Verificati’
Telnet(localhost,61823): recv b’onrnrnUsername: ‘
Telnet(localhost,61823): send b’USERn’
Telnet(localhost,61823): recv b’xffxfcx01xffxfcx03xffxfex18xffxfex1fUSERrnPassword: ‘
Telnet(localhost,61823): IAC WONT 1
Telnet(localhost,61823): IAC WONT 3
Telnet(localhost,61823): IAC DONT 24
Telnet(localhost,61823): IAC DONT 31
Telnet(localhost,61823): send b’passwordn’
Telnet(localhost,61823): send b’show clock n’
Telnet(localhost,61823): recv b’rn% Login invalidrnrnUsername: show clock rnPasswo’

% Login invalid

Username: show clock
Passwo

Process finished with exit code 0

from sshtunnel import open_tunnel
from telnetlib import Telnet
import os
import getpass
import time

ssh = 'x.x.x.x'
ssh_usr = "userssh"
ssh_pass = "passwordssh"
rem_host = 'x.x.x.x'
#user = input("Enter your remote account: ")
#password = getpass.getpass()

with open_tunnel(
    ssh_address_or_host=(ssh, 22),
    ssh_username=userssh,
    ssh_password=passwordssh,
    remote_bind_address=(rem_host, 23)
) as tunnel:
   # Use localhost as host
    with Telnet('localhost', tunnel.local_bind_port, 10) as tn:
        tn.set_debuglevel(5)
        tn.read_until(b"Username: ")
        #
        ##tn.write(user.encode('ascii') + b"n")
        tn.write(b'USERn')
        time.sleep(1)
        tn.read_until(b"Password: ")

        ##tn.write(password.encode('ascii') + b"n")
        tn.write(b'passwordn')
        time.sleep(1)
        #tn.write(b"usern")
        time.sleep(1)
        tn.write(b'show clock n')
        time.sleep(1)
        #output = tn.read_until("exit")
        print(tn.read_some().decode('ascii'))