net::telnet pm issue

Discussion in 'Perl Misc' started by solaris.identity@gmail.com, Feb 9, 2007.

  1. Guest

    Hi,

    Not matter what RE I try in 'waitfor' function does not match the
    "Password" prompt.


    Here is the piece of code, from your example that I used

    ## Create a Net::Telnet object to perform I/O on ssh's tty.
    use Net::Telnet;
    $ssh = new Net::Telnet (-fhopen => $pty,
    -prompt => $prompt,
    -telnetmode => 0,
    -cmd_remove_mode => 1,
    -output_record_separator => "\r");
    $ssh->dump_log('passwd.log');
    ## Login to remote host.
    $ssh->waitfor(-match => '/.*password:.*/i',
    -errmode => "return")
    or die "problem connecting to host: ", $ssh->lastline


    when I do a ssh from command line the prompt ends with

    Password:

    here are the last few line of dump_log

    < 0x00000: 50 65 72 6d 69 73 73 69 6f 6e 20 64 65 6e 69 65
    Permission denie
    < 0x00010: 64 20 28 67 73 73 61 70 69 2d 6b 65 79 65 78 2c d
    (gssapi-keyex.
    < 0x00020: 67 73 73 61 70 69 2d 77 69 74 68 2d 6d 69 63 2c gssapi-
    with-mic.
    < 0x00030: 70 75 62 6c 69 63 6b 65 79 2c 6b 65 79 62 6f 61
    publickey.keyboa
    < 0x00040: 72 64 2d 69 6e 74 65 72 61 63 74 69 76 65 29 2e rd-
    interactive).

    < 0x00000: 0d 0d 0a ...


    Thanks
     
    , Feb 9, 2007
    #1
    1. Advertising

  2. J. Gleixner Guest

    wrote:
    > Hi,
    >
    > Not matter what RE I try in 'waitfor' function does not match the
    > "Password" prompt.
    >
    >
    > Here is the piece of code, from your example that I used
    >
    > ## Create a Net::Telnet object to perform I/O on ssh's tty.
    > use Net::Telnet;
    > $ssh = new Net::Telnet (-fhopen => $pty,

    [...]
    > when I do a ssh from command line the prompt ends with
    >
    > Password:


    When running ssh, from the command line, it's not the
    same as telnet'ing to the port. Try it.. telnet
    to the port.

    If you're going to use SSH, then use the appropriate module.
     
    J. Gleixner, Feb 9, 2007
    #2
    1. Advertising

  3. Guest


    > When running ssh, from the command line, it's not the
    > same as telnet'ing to the port. Try it.. telnet
    > to the port.
    >
    > If you're going to use SSH, then use the appropriate module.- Hide quoted text -


    Sorry, I don't understand what you are saying, this method was taken
    directly from Net::Telnet module doc.

    Thanks
     
    , Feb 9, 2007
    #3
  4. Joe Smith Guest

    wrote:

    > Not matter what RE I try in 'waitfor' function does not match the
    > "Password" prompt.


    You're assuming that it comes over the socket.

    > $ssh = new Net::Telnet (-fhopen => $pty,
    >
    > when I do a ssh from command line the prompt ends with
    >
    > Password:


    With telnet, the "Password:" prompt comes over the socket from the telnetd server.
    With ssh, the "Password:" prompt comes from the ssh client and is read
    from /dev/tty, not STDIN.

    What made you choose Net::Telnet versus Net::SSH ?

    -Joe
     
    Joe Smith, Feb 9, 2007
    #4
  5. Guest

    On Feb 9, 4:26 pm, Joe Smith <> wrote:
    > wrote:
    > > Not matter what RE I try in 'waitfor' function does not match the
    > > "Password" prompt.

    >
    > You're assuming that it comes over the socket.
    >
    > > $ssh = new Net::Telnet (-fhopen => $pty,

    >
    > > when I do a ssh from command line the prompt ends with

    >
    > > Password:

    >
    > With telnet, the "Password:" prompt comes over the socket from the telnetd server.
    > With ssh, the "Password:" prompt comes from the ssh client and is read
    > from /dev/tty, not STDIN.
    >
    > What made you choose Net::Telnet versus Net::SSH ?
    >
    > -Joe



    I took this straight out of Net::Telnet web page examples

    http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm#AUTHOR


    there was no particular reason for using Net::Telnet. I found what I
    wanted to do with an example .

    here it is
    ## Main program.
    {
    my ($pty, $ssh, @lines);
    my $host = "changeme";
    my $user = "changeme";
    my $password = "changeme";
    my $prompt = '/changeme:~> $/';

    ## Start ssh program.
    $pty = &spawn("ssh", "-l", $user, $host); # spawn() defined
    below

    ## Create a Net::Telnet object to perform I/O on ssh's tty.
    use Net::Telnet;
    $ssh = new Net::Telnet (-fhopen => $pty,
    -prompt => $prompt,
    -telnetmode => 0,
    -cmd_remove_mode => 1,
    -output_record_separator => "\r");

    ## Login to remote host.
    $ssh->waitfor(-match => '/password: ?$/i',
    -errmode => "return")
    or die "problem connecting to host: ", $ssh->lastline;
    $ssh->print($password);
    $ssh->waitfor(-match => $ssh->prompt,
    -errmode => "return")
    or die "login failed: ", $ssh->lastline;

    ## Send command, get and print its output.
    @lines = $ssh->cmd("who");
    print @lines;

    exit;
    } # end main program

    sub spawn {
    my(@cmd) = @_;
    my($pid, $pty, $tty, $tty_fd);

    ## Create a new pseudo terminal.
    use IO::pty ();
    $pty = new IO::pty
    or die $!;

    ## Execute the program in another process.
    unless ($pid = fork) { # child process
    die "problem spawning program: $!\n" unless defined $pid;

    ## Disassociate process from existing controlling
    terminal.
    use POSIX ();
    POSIX::setsid
    or die "setsid failed: $!";

    ## Associate process with a new controlling terminal.
    $tty = $pty->slave;
    $tty_fd = $tty->fileno;
    close $pty;

    ## Make stdio use the new controlling terminal.
    open STDIN, "<&$tty_fd" or die $!;
    open STDOUT, ">&$tty_fd" or die $!;
    open STDERR, ">&STDOUT" or die $!;
    close $tty;

    ## Execute requested program.
    exec @cmd
    or die "problem executing $cmd[0]\n";
    } # end child process

    $pty;
    } # end sub spawn
     
    , Feb 10, 2007
    #5
  6. J. Gleixner Guest

    wrote:
    >> When running ssh, from the command line, it's not the
    >> same as telnet'ing to the port. Try it.. telnet
    >> to the port.
    >>
    >> If you're going to use SSH, then use the appropriate module.- Hide quoted text -

    >
    > Sorry, I don't understand what you are saying, this method was taken
    > directly from Net::Telnet module doc.


    So it was... hmmmm...

    My suggestion would be to use either Net::SSH, or Net:SSH::perl
    module. They provide a much better interface. If you have
    your keys set up, your code might be as simple as:

    use Net::SSH qw(ssh);
    ssh('user@hostname', 'some command');

    http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm
    http://search.cpan.org/~dbrobins/Net-SSH-Perl-1.30/lib/Net/SSH/Perl.pm
     
    J. Gleixner, Feb 12, 2007
    #6
    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:
    623
    Default User
    Nov 5, 2004
  2. Alex Ciarlillo

    telnet terminal issue

    Alex Ciarlillo, Nov 27, 2006, in forum: Ruby
    Replies:
    0
    Views:
    160
    Alex Ciarlillo
    Nov 27, 2006
  3. Marcin Tyman

    Telnet issue

    Marcin Tyman, Jul 24, 2007, in forum: Ruby
    Replies:
    2
    Views:
    95
    Marcin Tyman
    Jul 24, 2007
  4. Carcarius
    Replies:
    0
    Views:
    322
    Carcarius
    Dec 6, 2007
  5. Josh Hurtado

    Net::Telnet into Net::SSH

    Josh Hurtado, May 26, 2011, in forum: Ruby
    Replies:
    4
    Views:
    646
    Brian Candler
    May 27, 2011
Loading...

Share This Page