Frage

I'm trying to telnet from Linux to Windows PC but it's showing error "login failed".

Here is my Python script. I am using pexpect module. I also tried with telnetlib but same error:

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"

Error :

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
War es hilfreich?

Lösung

@vish You can debug the problem using wireshark according to Marcin.You just try below mentioned code as i already had the same problem and i got the solution

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

I hope this will work.

Andere Tipps

I can suggest an easy way to debug the problem. You wrote that it is possible to log in manually. If so, sniff telnet messages while logging manually with Wireshark. Sniff again after starting your script. Compare 2 traces. After comparing you should be able to tell what is missing in case of your script telnet messages.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top