2

我正在尝试使用 python 脚本(pexpect)从 linux 远程登录 Windows pc。当我尝试连接此错误时弹出 操作成功完成...登录失败下面是我的 python 脚本。

import pexpect,time,sys
from ftplib import FTP
def tel(ipadrr,login,password):

        try:    
                global telconn
                telconn = pexpect.spawn(ipadrr)
                telconn.logfile = open("/tmp/telnetlog", "a") 

                print "connected to telnet"
                print
        except:
                print "telconnnet connection refused"
                print 
                sys.exit() 

        try:
                time.sleep(15)
                #telconn.expect(": ")
                print "username"
                telconn.sendline(login + '\r')
                telconn.expect(":")
                print "password"
                telconn.sendline(password + '\r')
                #telconn.sendline("\r")
                #time.sleep(30)
                telconn.expect(">") 
                print "Authentication Sucesss"
                print
        except:
                print "Authentication Failure"
                print        
                sys.exit()
4

2 回答 2

1

我认为您的密码不是通过脚本输入的。尝试,

telconn.sendline(password + '\n')
于 2013-05-02T08:00:26.160 回答
1

@vish ..它已经回答了同样的问题..请验证相同

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(">")
于 2013-05-28T05:59:00.957 回答