Automating a password reset via net-telnet

Discussion in 'Ruby' started by Daniel Berger, Jul 10, 2007.

  1. Hi all,

    I'm trying to automate a password reset via telnet for a report. This
    happens twice per year, and right now I'm handling things manually. My
    attempts so far have been unsuccessful. Here's what I've tried:

    require 'net/telnet'
    include Net

    session = Telnet.new("Host" => host, "Output_log" =>
    'ftp_test.output')
    session.login(user, pass)

    session.cmd("passwd")
    #session.cmd("String" => "passwd", "Match" => /password:/i) # Tried
    this, too

    session.puts("old_password")
    session.puts("new_password")
    session.puts("new_password")

    session.close

    But, this doesn't seem to work. The output file shows that it's
    waiting for the current password, but the program fails with a timeout
    error. If I use the second cmd variant that I showed above, the script
    fails silently.

    Any ideas?

    Thanks,

    Dan
     
    Daniel Berger, Jul 10, 2007
    #1
    1. Advertising

  2. [SOLVED] Automating a password reset via net-telnet

    On Jul 10, 10:58 am, Daniel Berger <> wrote:
    > Hi all,
    >
    > I'm trying to automate a password reset via telnet for a report. This
    > happens twice per year, and right now I'm handling things manually. My
    > attempts so far have been unsuccessful.


    <snip>

    The documentation from Perl's Net::Telnet module suggested, for
    interactive programs, to always use puts/print + waitfor. So, I went
    with that approach. Here's what ultimately succeeded:

    require 'net/telnet'
    include Net

    session = Telnet.new("Host" => host)
    session.login(user, "XXXX")
    session.puts("passwd")

    session.waitfor(/existing login password:\s*/im)
    session.puts(current_password)

    session.waitfor(/new password:\s*/im)
    session.puts(new_password)

    session.waitfor(/new password:\s*/im)
    session.puts(new_password)

    session.waitfor(/password successfully changed/) # !!!

    session.close

    Note the multi-line regexes - that was crucial. Also, be sure to wait
    for the success message. If you don't your session will close too
    early and it will appear that your program succeeded, when in fact it
    did not.

    Regards,

    Dan
     
    Daniel Berger, Jul 10, 2007
    #2
    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. Jim Isaacson
    Replies:
    5
    Views:
    606
    Default User
    Nov 5, 2004
  2. Samuel
    Replies:
    1
    Views:
    909
    Samuel
    Jun 4, 2007
  3. AAaron123
    Replies:
    2
    Views:
    2,199
    AAaron123
    Jan 16, 2009
  4. Mike Mahon
    Replies:
    0
    Views:
    127
    Mike Mahon
    Mar 14, 2005
  5. Carcarius
    Replies:
    0
    Views:
    299
    Carcarius
    Dec 6, 2007
Loading...

Share This Page