为什么我的 Net::Telnet 程序超时?

发布于 2024-08-27 05:58:43 字数 835 浏览 6 评论 0原文

我编写了一些小代码来使用 Perl 连接到远程服务器,但观察错误消息

#!/usr/bin/perl -w

use Net::Telnet;

$telnet = new Net::Telnet ( Timeout=>60, Errmode=>'die');

$telnet->open('192.168.50.40');

$telnet->waitfor('/login:/');

$telnet->print('queen');

$telnet->waitfor('/password:/');

$telnet->print('kinG!');

$telnet->waitfor('/:/');

$telnet->print('vol >> C:\result.txt');

$telnet->waitfor('/:/');

$telnet->cmd("mkdir vol");

$telnet->print('mkdir vol234');

$telnet->cmd("mkdir vol1");

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

$telnet->print('whoamI');

print $output;

但是在运行时我收到以下错误

C:\>perl -c E:\test\net.pl

E:\test\net.pl syntax OK

C:\>perl E:\test\net.pl

command timed-out at E:\test\net.pl line 13

C:\>

在这方面帮助我。我是 Perl 新手。

I'm written small code to connect to remote server using Perl but observing error messages

#!/usr/bin/perl -w

use Net::Telnet;

$telnet = new Net::Telnet ( Timeout=>60, Errmode=>'die');

$telnet->open('192.168.50.40');

$telnet->waitfor('/login:/');

$telnet->print('queen');

$telnet->waitfor('/password:/');

$telnet->print('kinG!');

$telnet->waitfor('/:/');

$telnet->print('vol >> C:\result.txt');

$telnet->waitfor('/:/');

$telnet->cmd("mkdir vol");

$telnet->print('mkdir vol234');

$telnet->cmd("mkdir vol1");

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

$telnet->print('whoamI');

print $output;

But while running i'm getting following errors

C:\>perl -c E:\test\net.pl

E:\test\net.pl syntax OK

C:\>perl E:\test\net.pl

command timed-out at E:\test\net.pl line 13

C:\>

Help me in this regard. I'm new to Perl.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

但可醉心 2024-09-03 05:58:43

我不确定 Net::Telnet,但使用“/:/”(带引号)我猜是问题所在。即 /:/ (斜杠内) - 这是正则表达式,但带有引号,它只是应该出现在终端上的字符串(即它等待字符串“/:/” - 斜杠,两个点,斜杠)。

要调试此类程序(如果 Net::Telnet 不回显与远程系统的交互),您可以简单地输入: 在 waitfor() 之前的行中打印“我正在等待登录...\n”

I'm not sure about that Net::Telnet, but using '/:/' (with quotes) I guess is the problem. I.e. /:/ (within slashes) - that's regular expression, but with quotes that's simply string which should appear on terminal (i.e. it waits for string '/:/' - slash, two dots, slash).

To debug such programs (if Net::Telnet doesn't echo interaction with remote system) you can simply put: print "I'm waiting for login...\n" at lines before waitfor()

深空失忆 2024-09-03 05:58:43

您为什么不使用 Net::Telnet登录登录方法?当你水平这么低的时候,所有的细节都得自己处理。如果您查看该方法的源代码,您会发现它做了相当多的工作,包括解决 Linux 上登录错误的拼凑。

Why aren't you using Net::Telnet's login method to log-in? When you're at such a low level, you have to handle all of the details yourself. If you look in the source for that method, you'll see it doing quite a bit of work, including a kludge to get around a login bug on Linux.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文