|
发表于 2016-7-21 17:42:46
|
显示全部楼层
python3.5.1 版本,如下代码运行:
import getpass
import telnetlib
HOST = input("输入远程服务器的IP地址:")
user = input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until("password: ")
tn.write(password.encode('ascii') + "\n")
tn.write("show ver\n")
tn.write("exit\n")
print(tn.read_all().decode('ascii'))
运行出错如下:
Warning (from warnings module):
File "C:\Python35-32\lib\getpass.py", line 101
return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
Password: hillstone
Traceback (most recent call last):
File "F:/book/PYTHON/视频笔记/小实验/telnet3.py", line 10, in <module>
tn.read_until("login: ")
File "C:\Python35-32\lib\telnetlib.py", line 302, in read_until
i = self.cookedq.find(match)
TypeError: a bytes-like object is required, not 'str'
>>>
请高手帮忙看看代码,多谢 |
|