我想从远程登录一台Windows PC使用Python脚本(pexpect)。当我尝试连接此错误弹出的操作成功完成...登录失败下面是我的python脚本。远程登录从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()
参数)应该是一个命令例如telnet 127.0.0.1。为什么不使用telnetlib模块? – vszurma 2013-05-02 06:46:54
请发布一次运行的完整输出。 @tecjam也正确地将完整的命令提供给.spawn()。 – Dave 2013-05-02 06:57:33
Hi nolen 我已经在下面的程序中定义了def'tel'的值。 进口telnetftp,FTP,电话 进口Pexpect,第一次,从FTPLIB进口FTP telnetlib telnetftp.tel( “远程登录192.0.0.105”, “USR”, “通过@ 123”。 我已经尝试与telnetlib模块但显示相同的错误 – Vishnu 2013-05-02 07:01:50