超时等待登录提示Telnet Perl

时间:2016-06-28 14:29:45

标签: regex perl telnet

使用perl

登录telnet提示符时出现问题

这是我的提示:

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

Enter username and password
>

这是我的代码:

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;

但我有一条消息错误:超时等待登录提示

我尝试使用:

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

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

任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

我解决了我的问题:D

它适用于我:

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');

在我的情况下句子$t->login('test', 'test1');不起作用,然后我尝试在同一行$t->print('test test1');上写usr和pw并且它有效!