【发布时间】:2014-10-19 19:37:46
【问题描述】:
我现在正在尝试在 Python 3.4 中使用 telnetlib。 我想要的只是尝试向我的接入点发送命令并获得一些响应。 我的代码:
`import telnetlib
import time
user='admin'
password='admin'
host='192.168.1.1'
try:
tn=telnetlib.Telnet("host")
tn.read_until(b"Login: ")
tn.write(user.encode() + "\r\n".encode())
tn.read_until(b"Password: ")
tn.write(password.encode() + "\r\n".encode())
print("Connection establised")
except Exception:
print("Connection failed")
cmd="interface AccessPoint\r\n"
tn.write(cmd.encode())
cmd2="ssid TEST\r\n"
tn.write(cmd2.encode())
output=n.read_eager()
while output:
print(output.decode())
time.sleep(.2)
output=tn.read_eager()
` 例如,此脚本应将 SSID 的名称更改为 TEST。 然后我在Putty中做,就可以了:
但后来我试图从我的脚本中读取响应,我看到的是这样的:
请告诉我所有这些符号是什么意思? 有没有办法从我的原木中删除它们?
附:尝试了所有其他的阅读方式,比如 read_all。尝试不使用 decode(),尝试使用 decode('utf-8'),但符号总是在这里。我还应该做什么?
谢谢你,梅里。
【问题讨论】:
-
您的问题中不需要
`和 块缩进。对内联代码使用反引号,对多行代码块使用缩进。缩进一大段代码的一种简单方法是全选,然后在文本编辑器上方的工具栏中按{}。 -
谢谢,下次会做的更好。)