Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > telnet session

Reply
Thread Tools

telnet session

 
 
eight02645999@yahoo.com
Guest
Posts: n/a
 
      03-29-2006
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?

 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      03-29-2006
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.
 
Reply With Quote
 
 
 
 
Eddie Corns
Guest
Posts: n/a
 
      03-29-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Telnet - attempting to initiate a telnet session within an established telnet session Carcarius Ruby 0 12-06-2007 03:26 AM
Help about router's Telnet session BB Cisco 1 01-04-2005 05:39 AM
Need to talk to a telnet server and send a telnet break Jim Isaacson C Programming 5 11-05-2004 09:17 PM
Unable to type in AS5300 telnet session Matt Cisco 3 06-15-2004 04:27 PM
How can I telnet when I dont have specific access to a telnet client Jack B. Pollack Computer Support 4 07-24-2003 08:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57