Im am attempting to use the python telnetlib library to connect to a virtual router that I have installed on my machine with VMWARE pro. I am able to ping the virtual router via its G0/2 interface ip address 10.2.162.206.
When I run my script that is intended to connect to the vritual router and run the "show users" command I get nothing back and then terminates the connection after a few minutes.
import getpass
import telnetlib
HOST = "10.2.162.206"
user = 'Cisco1'
password = 'class1'
def show_users_telnet():
'''Return logged in users'''
tn = telnetlib.Telnet(HOST)
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.read_until(b'#')
tn.write(b'show users\n')
stdout = tn.read_until(b'#').decode('utf-8')
print(stdout)
show_users_telnet()
I am also attaching a screenshot of the virtual routers interfaces which I can ping.
This is the output from vscode
Traceback (most recent call last): File "C:\Users\xxxxxx\OneDrive - xxxx xxx\Documents\Universidad\AdmindeRedes\telnet-1.py", line 25, in show_users_telnet() File "C:\Users\xxxxxx\OneDrive - xxxx xxx\Documents\Universidad\AdmindeRedes\telnet-1.py", line 19, in show_users_telnet 3568.0_x64__qbz5n2kfra8p0\lib\telnetlib.py", line 315, in read_until if selector.select(timeout): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\selectors.py", line 324, in select r, w, _ = self._select(self._readers, self._writers, [], timeout) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\selectors.py", line 315, in _select r, w, x = select.select(r, w, w, timeout) KeyboardInterrupt