Search code examples
regexperltelnet

timed-out waiting for login prompt Telnet Perl


I have a problem to log in into a telnet prompt using perl

this is my prompt:

Trying 192.168.10.15...
Connected to 192.168.10.15.
Escape character is '^]'.

Enter username and password
>

And this is my code:

use Net::Telnet ();
$t = new Net::Telnet (Port => 11052, Timeout => 10, Prompt => '/Enter username and password/ /\n/ /> $/i');
$t->open("192.168.10.15");
$t->login('test', 'test1');
@lines = $t->cmd("ls");
print @lines;

But I have a message error: timed-out waiting for login prompt

I tried using:

$t->waitfor('/Enter username and password/ /\n/ /> $/i');

and

$->waitfor('/> $/i');

can anybody help me with this?


Solution

  • I solved my problem :D

    It works for me using:

    use Net::Telnet ();
    $t = new Net::Telnet (Host=> "192.168.10.15", Port => 11052, Timeout => 5, Prompt => "/Enter username and password/");    
    $t->waitfor('/Enter username and password/'); 
    $t->print('test test1');
    

    In my case the sentence $t->login('test', 'test1'); doesn't work, then I tried writing usr and pw on the same line $t->print('test test1'); and it works!