开发者

telnet inline with perl?

开发者 https://www.devze.com 2023-01-13 02:02 出处:网络
Is there a way to allow perl to initiate a telnet session and programmatically issue commands to that telnet session?

Is there a way to allow perl to initiate a telnet session and programmatically issue commands to that telnet session?

I initially tried a stupid method:

commands.pl:

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

and then

> perl commands.pl | telnet 开发者_开发知识库www.host.com port

This does not work.


There is a Net::Telnet module.

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

(Example taken from that page.)


One option would be through Perl's interface to Expect.

0

精彩评论

暂无评论...
验证码 换一张
取 消