【问题标题】:telnet inline with perl?telnet 与 perl 内联?
【发布时间】:2011-04-04 14:08:51
【问题描述】:

有没有办法让 perl 启动一个 telnet 会话并以编程方式向该 telnet 会话发出命令?

我最初尝试了一个愚蠢的方法:

commands.pl:

sleep(1);
print $command1;
sleep(1);
print $command2;

然后

> perl commands.pl | telnet www.host.com port

这不起作用。

【问题讨论】:

    标签: perl telnet


    【解决方案1】:

    有一个Net::Telnet 模块。

    use Net::Telnet ();
    $t = new Net::Telnet (Timeout => 10,
                          Prompt => '/bash\$ $/');
    $t->open("sparky");
    $t->login($username, $passwd);
    @lines = $t->cmd("who");
    print @lines;
    

    (取自该页面的示例。)

    【讨论】:

      【解决方案2】:

      一种选择是通过Perl's interface to Expect

      【讨论】:

        猜你喜欢
        • 2015-02-06
        • 2011-10-25
        • 2013-08-26
        • 2016-03-07
        • 1970-01-01
        • 2012-09-18
        • 2012-11-09
        • 1970-01-01
        • 2013-06-23
        相关资源
        最近更新 更多