telnet session

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eight02645999@yahoo.com

    #1

    telnet session

    hi
    i am using a telnet session to simulate an authentication mechanism
    USER = "user"
    PASSWORD = "password"
    try:
    telnet = telnetlib.Telne t(HOST)
    telnet.set_debu glevel(5)
    telnet.read_unt il("login: ")
    telnet.write(US ER + "\n")
    telnet.read_unt il("Password: ")
    telnet.write(PA SSWORD + "\n")
    except:
    print "failed to telnet"
    else:
    try:
    telnet.write("l s\n")
    except:
    print "cannot ls"
    else:
    telnet.write("e xit\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?

  • Paul Rubin

    #2
    Re: telnet session

    eight02645999@y ahoo.com writes:[color=blue]
    > 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?[/color]


    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.

    Comment

    • Eddie Corns

      #3
      Re: telnet session

      eight02645999@y ahoo.com writes:
      [color=blue]
      >hi
      >i am using a telnet session to simulate an authentication mechanism
      >USER = "user"
      >PASSWORD = "password"
      >try:
      > telnet = telnetlib.Telne t(HOST)
      > telnet.set_debu glevel(5)
      > telnet.read_unt il("login: ")
      > telnet.write(US ER + "\n")
      > telnet.read_unt il("Password: ")
      > telnet.write(PA SSWORD + "\n")
      >except:
      > print "failed to telnet"
      >else:
      > try:
      > telnet.write("l s\n")
      > except:
      > print "cannot ls"
      > else:
      > telnet.write("e xit\n")
      > print telnet.read_all ()[/color]

      [color=blue]
      >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?[/color]

      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("Pas sword:") and if it times out then assume you got through.

      Comment

      Working...