문제

i have an issue while running my telnet script using pexpect.Problem is its taking only username from script not password.Its taking the value of password but its not entering the same.Mentioned below my script,

import pexpect
import sys,time
ipaddr = "192.168.100.85"
username = "usr"
password = "Pass@123"
telconn = pexpect.spawn("telnet " + ipaddr)
telconn.expect(":")
telconn.logfile=sys.stdout
time.sleep(15)
telconn.sendline(username + "\r")
telconn.expect(":")
telconn.sendline(password + "\r")
time.sleep(30)
telconn.expect(">")
print "Authentication Sucesss"

Output of this,

Trying 192.168.100.85...
Connected to 192.168.100.85.
Escape character is '^]'.
Welcome to Microsoft Telnet Service 


login: usr

password: Pass@123

The operation completed successfully.

Login Failed
도움이 되었습니까?

해결책

I got solution for this,

import pexpect
import time,sys
telconn = pexpect.spawn('telnet 192.168.100.85')
time.sleep(20)
telconn.logfile = sys.stdout
telconn.expect(":")
time.sleep(20)
telconn.send("usr" + "\r")
telconn.expect(":")
telconn.send("Pass@123" + "\r")
telconn.send("\r\n")
time.sleep(20)
telconn.expect(">")

This worked for me

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top