Recently i have started learning python, and currently working on a small script to remote telnet from physical laptop to a router in GNS. Every connectivity is fine and i am able to telnet to the router via CMD using telnet command.
But when i am running my script instead of direct telnet command that where i am facing issue. Program runs fine without any issue, but telnet does not work.
I tried running debug as well on router can someone please check the script code and output from the debug command and advise what could be possible wrong.
SCRIPT CODE:
import getpass
import sys
import telnetlib
HOST = "192.168.1.7"
tn =telnetlib.Telnet("192.168.1.7", "23")
user = input("Enter your username: ")
password = getpass.getpass()
tn.read_until(b"Username: ")
tn.write(user.encode("ASCII") + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write (password.encode("ASCII") + b"\n")
OUTPUT OF DEBUG TELNET COMMAND ON CISCO:
R2
*Aug 6 16:50:15.095: Telnet2: 1 1 251 1
*Aug 6 16:50:15.095: TCP2: Telnet sent WILL ECHO (1)
*Aug 6 16:50:15.095: Telnet2: 2 2 251 3
*Aug 6 16:50:15.095: TCP2: Telnet sent WILL SUPPRESS-GA (3)
*Aug 6 16:50:15.095: Telnet2: 80000 80000 253 24
*Aug 6 16:50:15.099: TCP2: Telnet sent DO TTY-TYPE (24)
*Aug 6 16:50:15.099: Telnet2: 10000000 10000000 253 31
*Aug 6 16:50:15.099: TCP2: Telnet sent DO WINDOW-SIZE (31)
R2
*Aug 6 16:50:23.451: TCP2: Telnet received DONT ECHO (1)
*Aug 6 16:50:23.451: TCP2: Telnet sent WONT ECHO (1)
*Aug 6 16:50:23.539: TCP2: Telnet received DONT SUPPRESS-GA (3)
*Aug 6 16:50:23.539: TCP2: Telnet sent WONT SUPPRESS-GA (3)
*Aug 6 16:50:23.543: TCP2: Telnet received WONT TTY-TYPE (24)
*Aug 6 16:50:23.543: TCP2: Telnet sent DONT TTY-TYPE (24)
*Aug 6 16:50:23.543: TCP2: Telnet received WONT WINDOW-SIZE (31)
*Aug 6 16:50:23.547: TCP2: Telnet sent DONT WINDOW-SIZE (31)
*Aug 6 16:50:23.567: TCP2: Telnet received DONT ECHO (1)
*Aug 6 16:50:23.571: TCP2: Telnet received DONT SUPPRESS-GA (3)
*Aug 6 16:50:23.571: TCP2: Telnet received WONT TTY-TYPE (24)
R2
*Aug 6 16:50:23.571: TCP2: Telnet received WONT WINDOW-SIZE (31)
R2