Python 不能从linux pc远程登录到windows pc”;登录失败错误“;

Python 不能从linux pc远程登录到windows pc”;登录失败错误“;,python,telnet,pexpect,Python,Telnet,Pexpect,我正在尝试从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.sle

我正在尝试从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

我可以建议一种简单的方法来调试这个问题。您写道可以手动登录。如果是这样,则在使用Wireshark手动登录时嗅探telnet消息。启动脚本后再次嗅探。比较两条轨迹。在比较之后,您应该能够告诉您的脚本telnet消息缺少什么

我可以建议一种简单的方法来调试这个问题。您写道可以手动登录。如果是这样,则在使用Wireshark手动登录时嗅探telnet消息。启动脚本后再次嗅探。比较两条轨迹。在比较之后,您应该能够告诉您的脚本telnet消息缺少什么

@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(">")
我希望这能奏效。

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

我希望这能起作用。

请记住,上面说的行尾是
'\r\n'
。另外,您可以手动登录吗?@joachim是的,我尝试了\r\n,也可以手动登录…@user我终止了进程并尝试了相同的错误…请记住,上面说的行尾是
'\r\n'
,您可以手动登录吗?@joachim是的,我尝试了使用\r\n,也可以手动登录…@user我终止了进程并尝试了,但出现了相同的错误。。。。