質問

  1. I need to get a connection to a device via TELNET and write in to telnet session.
  2. I Use - Python 3.3.2 and PyDev For Eclipse 2.7.5
  3. I use IP2COM cause it allows me to open another telnet to the same device and see how the commands are executed.

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())

他のヒント

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

Try this.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top