Hello,
I am just playing around in GNS3 and having issues with telnetting in from an Ubuntu docker using a Python script, to a router. I have confirmed connectivity and they are both setup with NAT to hit external sites successfully. I can also telnet from the router to the same router (for testing purposes), so I know it's working. Here is my script, which is basically a slightly edited version from the example: https://docs.python.org/3/library/telnetlib.html
import getpass import telnetlib
HOST = "10.168.122.223" user = input("Enter your telnet password: ") 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"ls\n") tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))
When I execute the above, the following error comes back:
root@UbuntuDockerGuest-2:~# python PythonR1Script1 Enter your telnet username: joe Traceback (most recent call last): File "PythonR1Script1", line 6, in user = input("Enter your telnet username: ") File "", line 1, in NameError: name 'joe' is not defined
I am following David Bombal's Python for Networking Engineers here, https://www.youtube.com/watch?v=IhroIrV9_7w&ab_channel=DavidBombal, and he is using virtually the same commands although he is using Python2 and I'm using Python3. Any help is much appreciated!
Simple Python Telnetlib Script in GNS3
11 Views Asked by StudyGuy At
0