telnet session

E

eight02645999

hi
i am using a telnet session to simulate an authentication mechanism
USER = "user"
PASSWORD = "password"
try:
telnet = telnetlib.Telnet(HOST)
telnet.set_debuglevel(5)
telnet.read_until("login: ")
telnet.write(USER + "\n")
telnet.read_until("Password: ")
telnet.write(PASSWORD + "\n")
except:
print "failed to telnet"
else:
try:
telnet.write("ls\n")
except:
print "cannot ls"
else:
telnet.write("exit\n")
print telnet.read_all()


When i purposely input a wrong password, it "hangs" at the login prompt
waiting for
login and Password. The host i am telnetting to is a unix server.
How can i "exit" this login prompt if the user keys in wrong password
in my script?
 
P

Paul Rubin

When i purposely input a wrong password, it "hangs" at the login prompt
waiting for
login and Password. The host i am telnetting to is a unix server.
How can i "exit" this login prompt if the user keys in wrong password
in my script?


It looks to me like after you send the wrong password, you send "ls"
without checking that you got back another login prompt. Then the
program hangs because both ends are waiting for input.

Whatever your actual application is, try to avoid doing it this way.
 
E

Eddie Corns

hi
i am using a telnet session to simulate an authentication mechanism
USER = "user"
PASSWORD = "password"
try:
telnet = telnetlib.Telnet(HOST)
telnet.set_debuglevel(5)
telnet.read_until("login: ")
telnet.write(USER + "\n")
telnet.read_until("Password: ")
telnet.write(PASSWORD + "\n")
except:
print "failed to telnet"
else:
try:
telnet.write("ls\n")
except:
print "cannot ls"
else:
telnet.write("exit\n")
print telnet.read_all()

When i purposely input a wrong password, it "hangs" at the login prompt
waiting for
login and Password. The host i am telnetting to is a unix server.
How can i "exit" this login prompt if the user keys in wrong password
in my script?

Either do an explicit read_until() for the prompt and fail if it times out or
use expect() to see whether you saw "Password:" or prompt. If you absolutely
don't know what the prompt might be I suppose you could do another
read_until("Password:") and if it times out then assume you got through.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top