The main purpose of this is to Read\Write in to Telnet session using Python.
Here is the code that i use:
import getpass
import sys
import telnetlib
HOST = "172.17.174.50"
port = "1003"
#user = input("Enter your remote account: ")
#password = getpass.getpass()
tn = telnetlib.Telnet(HOST, port)
#tn.read_until("user:")
#tn.write(user.encode('ascii') + b"\r")
#tn.write(user.encode("test" + "\r")
#if password:
# tn.read_until(b"Password: ")
# tn.write(password.encode('ascii') + b"\n")
tn.write("sh run" + "\r")
tn.write("exit" + "\r")
print(tn.read_all()
Here is the error that i'm getting :
File "C:\Users\user\workspace\main\src\telnet.py", line 23 ^ SyntaxError: unexpected EOF while parsing
The strange thing is that i have only 22 lines.. line number 23 is empty...
Can someone help me with that?
Thanks.
A parenthesis is missing in the last line.
print(tn.read_all())