After I run this code I'm able to enter host IP, the username and the password, but got this error:

Traceback (most recent call last): File "Test.py", line 17, in tn.read_until(b"Password: ") File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/telnetlib.py", line 327, in read_until return self.read_very_lazy() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/telnetlib.py", line 403, in read_very_lazy raise EOFError('telnet connection closed') EOFError: telnet connection closed

import getpass

import telnetlib

HOST = input("Enter the localhost: ")

user = input("Enter your remote account: ")

password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"login: ") tn.write(user.encode('ascii') + b"\n") if password: tn.read_until(b"Password: ") tn.write(password.encode('ascii') + b"\n")

tn.write("show run \n")

tn.write(b"sh sw\n") tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))

0 Answers