telnet inline with perl?
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.
精彩评论