telnet session

Discussion in 'Python' started by eight02645999@yahoo.com, Mar 29, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Paul Rubin Guest

    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.
     
    Paul Rubin, Mar 29, 2006
    #2
    1. Advertising

  3. Eddie Corns Guest

    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.
     
    Eddie Corns, Mar 29, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Lambert

    Starting a Telnet Session???

    Mike Lambert, Oct 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,284
    Hans Kesting
    Oct 22, 2003
  2. Michael
    Replies:
    1
    Views:
    2,683
    Attila Feher
    Jan 27, 2005
  3. Replies:
    5
    Views:
    19,852
  4. Jim Isaacson
    Replies:
    5
    Views:
    629
    Default User
    Nov 5, 2004
  5. Carcarius
    Replies:
    0
    Views:
    331
    Carcarius
    Dec 6, 2007
Loading...

Share This Page