I am telneting to a Cisco router via Python3. However, it hangs up after running the script (But I am able to telnet to the router from my Linux bash). Please see the snippets of my script and outputs below.
import getpass
import telnetlib
HOST = "10.10.32.3"
user = input("Enter your telnet username: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
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")
tn.write(b"conf t\n")
tn.write(b"int l0\n")
print(tn.read_all().decode('ascii'))
And this is the output of debug telnet
on the router
Router#
*Nov 2 23:48:24.317: Telnet578: 1 1 251 1
*Nov 2 23:48:24.318: TCP578: Telnet sent WILL ECHO (1)
*Nov 2 23:48:24.318: Telnet578: 2 2 251 3
*Nov 2 23:48:24.318: TCP578: Telnet sent WILL SUPPRESS-GA (3)
*Nov 2 23:48:24.318: Telnet578: 80000 80000 253 24
*Nov 2 23:48:24.319: TCP578: Telnet sent DO TTY-TYPE (24)
*Nov 2 23:48:24.319: Telnet578: 10000000 10000000 253 31
*Nov 2 23:48:24.319: TCP578: Telnet sent DO WINDOW-SIZE (31)
*Nov 2 23:48:24.383: TCP578: Telnet received DONT ECHO (1)
*Nov 2 23:48:24.383: TCP578: Telnet sent WONT ECHO (1)
*Nov 2 23:48:24.387: TCP578: Telnet received DONT SUPPRESS-GA (3)
*Nov 2 23:48:24.387: TCP578: Telnet sent WONT SUPPRESS-GA (3)
Router#
*Nov 2 23:48:24.389: TCP578: Telnet received WONT TTY-TYPE (24)
*Nov 2 23:48:24.389: TCP578: Telnet sent DONT TTY-TYPE (24)
*Nov 2 23:48:24.390: TCP578: Telnet received WONT WINDOW-SIZE (31)
*Nov 2 23:48:24.391: TCP578: Telnet sent DONT WINDOW-SIZE (31)
*Nov 2 23:48:24.407: TCP578: Telnet received DONT ECHO (1)
*Nov 2 23:48:24.407: TCP578: Telnet received DONT SUPPRESS-GA (3)
*Nov 2 23:48:24.407: TCP578: Telnet received WONT TTY-TYPE (24)
*Nov 2 23:48:24.408: TCP578: Telnet received WONT WINDOW-SIZE (31)
And the output of show tcp brief
Router#sho tcp brief
TCB Local Address Foreign Address (state)
10C90CE0 10.10.32.3.23 192.168.122.61.51466 ESTAB
I can create the loopback interface, but my Linux bash doesn't show me the telnet output. Please guide accordingly. Thank you.