timeout problem with Net::Telnet

Discussion in 'Perl Misc' started by Mr_Noob, Mar 11, 2008.

  1. Mr_Noob

    Mr_Noob Guest

    Hi all,

    Here is my perl script that make a telnet connection with a windows2k3
    box :


    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use Net::Telnet ();
    my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
    '/\$ $/i');

    # telnet credentials
    my $username = "administrator";
    my $password = "mypass";
    my $launcher = "c:\\\\my_bat_files\\\\test\\\\launcher.bat";
    my $server = "myserver";

    # Open telnet connection to $server
    $telnet->open($server);
    # telnet login/password
    $telnet->login($username, $password);
    # launch bat file
    print $telnet->cmd($launcher);

    But i have the following error :

    "timed-out waiting for command prompt at scripts/Sanstat_launcher.pl
    line 32"

    I guess my "Prompt" isn't set correctly but can't find how to correct
    this...
    Here is how it looks like if i telnet my server manually :


    $ telnet myserver
    Trying 192.168.1.6...
    Connected to myserver.mydomain.com.
    Escape character is '^]'.
    Welcome to Microsoft Telnet Service

    login: administrator
    password:

    *===============================================================
    Welcome to Microsoft Telnet Server.
    *===============================================================
    C:\Documents and Settings\Administrator>



    thx in advance for helping
     
    Mr_Noob, Mar 11, 2008
    #1
    1. Advertising

  2. Mr_Noob

    J. Gleixner Guest

    Mr_Noob wrote:
    > Hi all,
    >
    > Here is my perl script that make a telnet connection with a windows2k3
    > box :
    >
    >
    > #!/usr/bin/perl -w
    > use strict;
    > use warnings;
    > use Net::Telnet ();
    > my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
    > '/\$ $/i');


    That's saying that you want a prompt that ends with a '$ '.

    [...]
    > I guess my "Prompt" isn't set correctly but can't find how to correct
    > this...


    You change the regular expression of the Prompt attribute above.

    > Here is how it looks like if i telnet my server manually :
    >
    >
    > $ telnet myserver
    > Trying 192.168.1.6...
    > Connected to myserver.mydomain.com.
    > Escape character is '^]'.
    > Welcome to Microsoft Telnet Service
    >



    > login: administrator
    > password:


    Your prompt on the remote machine would be the 'login: ', then the
    'password: '.

    Modify your Prompt to match what you're seeing on the remote machine.
     
    J. Gleixner, Mar 11, 2008
    #2
    1. Advertising

  3. Mr_Noob

    Mr_Noob Guest

    On 11 mar, 16:15, "J. Gleixner" <>
    wrote:
    > Mr_Noob wrote:
    > > Hi all,

    >
    > > Here is my perl script that make a telnet connection with a windows2k3
    > > box :

    >
    > > #!/usr/bin/perl -w
    > > use strict;
    > > use warnings;
    > > use Net::Telnet ();
    > > my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
    > > '/\$ $/i');

    >
    > That's saying that you want a prompt that ends with a '$ '.
    >
    > [...]
    >
    > > I guess my "Prompt" isn't set correctly but can't find how to correct
    > > this...

    >
    > You change the regular expression of the Prompt attribute above.
    >
    > > Here is how it looks like if i telnet my server manually :

    >
    > > $ telnet myserver
    > > Trying 192.168.1.6...
    > > Connected to myserver.mydomain.com.
    > > Escape character is '^]'.
    > > Welcome to Microsoft Telnet Service

    >
    > > login: administrator
    > > password:

    >
    > Your prompt on the remote machine would be the 'login: ', then the
    > 'password: '.
    >
    > Modify your Prompt to match what you're seeing on the remote machine.



    ok, thx for the advise.
    But i tried this :

    my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
    '/login: $/i');

    or
    my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
    '/password:$/i');


    my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
    '/login:|password:$/i');

    without any success.....
     
    Mr_Noob, Mar 11, 2008
    #3
  4. Mr_Noob

    Ben Morrow Guest

    Quoth "J. Gleixner" <>:
    > Mr_Noob wrote:
    > >
    > > Here is my perl script that make a telnet connection with a windows2k3
    > > box :


    Have you read the notes in Net::Telnet about Microsoft's telnet server?

    > > #!/usr/bin/perl -w
    > > use strict;
    > > use warnings;
    > > use Net::Telnet ();
    > > my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>


    Using 'indirect object syntax' (new Net::Telnet (...)) is a bad idea.
    Perl's parsing of it is somewhat flakey, and it's better to use normal
    object syntax:

    my $telnet = Net::Telnet->new(...);

    > > '/\$ $/i');

    >
    > That's saying that you want a prompt that ends with a '$ '.

    <snip>
    >
    > Your prompt on the remote machine would be the 'login: ', then the
    > 'password: '.


    No, it wouldn't. Net::Telnet handles the login prompts itself. The
    prompt on a Win32 machine is something like qr/\\>$/ or qr/\\> $/: whatever
    the shell prints just before you enter a command.

    Ben
     
    Ben Morrow, Mar 11, 2008
    #4
  5. Mr_Noob

    szr Guest

    Ben Morrow wrote:
    > Quoth "J. Gleixner" <>:
    >> Mr_Noob wrote:
    >>>
    >>> Here is my perl script that make a telnet connection with a
    >>> windows2k3 box :

    >
    > Have you read the notes in Net::Telnet about Microsoft's telnet
    > server?
    >
    >>> #!/usr/bin/perl -w
    >>> use strict;
    >>> use warnings;
    >>> use Net::Telnet ();
    >>> my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt
    >>> =>

    >
    > Using 'indirect object syntax' (new Net::Telnet (...)) is a bad idea.
    > Perl's parsing of it is somewhat flakey, and it's better to use normal
    > object syntax:
    >
    > my $telnet = Net::Telnet->new(...);


    I have never had an issue using the indirect syntax. I find it more
    comfortable, having a c++/java background before I learned Perl some
    time ago. Exactly what difference does it make, if any (as I have never
    found any) ?

    --
    szr
     
    szr, Mar 12, 2008
    #5
  6. szr <> wrote:
    > Ben Morrow wrote:


    >> Using 'indirect object syntax' (new Net::Telnet (...)) is a bad idea.


    > I have never had an issue using the indirect syntax. I find it more
    > comfortable, having a c++/java background before I learned Perl some
    > time ago. Exactly what difference does it make, if any (as I have never
    > found any) ?



    See the "Indirect Object Syntax" section in perlobj.pod.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 12, 2008
    #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:
    628
    Default User
    Nov 5, 2004
  2. Mark Probert

    net/telnet problem

    Mark Probert, Sep 9, 2003, in forum: Ruby
    Replies:
    2
    Views:
    102
    Mark Probert
    Sep 10, 2003
  3. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,355
    Brian Candler
    Oct 6, 2004
  4. Carcarius
    Replies:
    0
    Views:
    329
    Carcarius
    Dec 6, 2007
  5. Josh Hurtado

    Net::Telnet into Net::SSH

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

Share This Page