python - 无法从 Linux 电脑 telnet 到 Windows 电脑 "login Failed error"

标签 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.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/

相关文章:

client - 跨操作系统远程登录客户端的远程登录库和语言选择?

python - Expect 无法生成两个以上的命令

python - 从实例方法更改日期时间字段的值

python - 整数线性规划+python+ubuntu

http - 如何将文件提供给telnet

telnet - 黑屏和错误 400 错误请求

python - 是否可以使用 pexpect 生成将显示在 bash 历史记录中的 bash shell 命令?

python - Pexpect,运行 ssh-copy-id 在尝试生成第二个进程时挂起

Python 记录完成/失败消息

python - 使用 re.split() 将一个字符串拆分为多个字符串