我正在尝试从 Linux 远程登录到 Windows PC,但显示错误“登录失败”。
这是我的 Python 脚本。我正在使用 pexpect
模块。我也尝试过使用 telnetlib
但同样的错误:
import os
import pexpect,time
telconn = pexpect.spawn('telnet 192.168.0.105')
telconn.logfile = open("/tmp/telnetlog", "a")
time.sleep(30)
print "connected"
telconn.expect(':')
telconn.sendline("user" + "\r")
#time.sleep(10)
print "connected user"
telconn.expect(':')
password = "user@123"
#print password
telconn.sendline(password + "\r")
time.sleep(60)
#print "connected password"
错误:
Connected to 192.168.0.105.
Escape character is '^]'.
Welcome to Microsoft Telnet Service
login: user
password: user@123
The operation completed successfully.
Login Failed
最佳答案
@vish 您可以根据Marcin使用wireshark调试问题。您只需尝试下面提到的代码,因为我已经遇到了同样的问题,并且我得到了解决方案
import pexpect
import time,sys
telconn = pexpect.spawn('telnet 192.168.0.105')
time.sleep(20)
telconn.logfile = sys.stdout
telconn.expect(":")
time.sleep(20)
telconn.send("user" + "\r")
telconn.expect(":")
telconn.send("user@123" + "\r")
telconn.send("\r\n")
time.sleep(20)
telconn.expect(">")
我希望这会起作用。
关于python - 无法从 Linux 电脑 telnet 到 Windows 电脑 "login Failed error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16558219/