467,219 Members | 1,416 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,219 developers. It's quick & easy.

telnet session

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?

Mar 29 '06 #1
  • viewed: 3685
Share:
2 Replies
ei***********@yahoo.com writes:
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.
Mar 29 '06 #2
ei***********@yahoo.com writes:
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.

Mar 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by kumar | last post: by
3 posts views Thread by Yannick Turgeon | last post: by
4 posts views Thread by Donnal Walter | last post: by
2 posts views Thread by john brown | last post: by
5 posts views Thread by richardtinkler | last post: by
5 posts views Thread by Greg Martz | last post: by
reply views Thread by eight02645999@yahoo.com | last post: by
2 posts views Thread by vmalhotra | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.