0

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!

StudyGuy
  • 29
  • 1
  • 3
  • Wow, I am a noob. I formatted the above so bad, and I apologize for that. I may need a lesson on how to propose coding questions lol. – StudyGuy May 18 '21 at 20:02
  • You can still fix it by using the [edit] button. – mkrieger1 May 18 '21 at 20:05
  • However, the solution seems simply to use `python3` instead of `python` to start the script. – mkrieger1 May 18 '21 at 20:08
  • This should answer your question: [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – mkrieger1 May 18 '21 at 20:09
  • Thank you guys. I feel a bit dumb on that one. I don't believe you have to specify that on Windows? But was using Ubuntu here so specified python3 (filename), and it worked like a charm. Thanks again! – StudyGuy May 19 '21 at 00:57

0 Answers0