0

Hi I am new to telnet package in python. My code works but not expected execution output contains extra alphanumerics. Final output should contain only 1.index and 2.comment. instead it prints:- f085467678G1.uGpindex_gvA3e5JGyhjejkn 9jhf2.syGtcomment_Gphjsyfufdfm. I am totally clueless

*code:**

import getpass
import telnetlib
import pyte


HOST = "http://localhost:8000/"
user = input("Enter your remote account: ")
password = getpass.getpass()
choice=[{'91':b"choice: "},{"90":b"choice: "}]
screen=pyte.Screen(80,24)
scIndex=1

def show1():
    global screen
    global scIndex
    for i,line in enumerate(screen.show1,1):

        print(line)

    screen.show1.clear()

stream=pyte.Stream(screen)
tn = telnetlib.Telnet(HOST)
a=tn.read_until(b"login: ")
stream.feed(a).decode("ISO-8856-1")
show1()
tn.write(user.encode("ISO-8856-1") + b"\n")
if password:
    b=tn.read_until(b"Password: ")
    stream.feed(b).decode("ISO-8856-1")
    show1()
    tn.write(password.encode("ISO-8856-1") + b"\n")

for cm in choice:
    for c in cm:
        tn.write(c.encode("ISO-8856-1")+b"\n")
        s=tn.read_until(cm[c])
        j=s.decode("ISO-8856-1")
        stream.feed(j)
        show1()
thimoni
  • 1
  • 3
  • Have you tried printing the stream you get directly from the `read_until` calls? I don't really understand why you are displaying to the screen and then reading from the screen. – Tim Roberts Apr 06 '21 at 06:42
  • HOST terminal screen size 80*24 So I read the same content as it is and feed the same in the console – thimoni Apr 06 '21 at 07:04

0 Answers0