Razor Storm
Razor Storm

Reputation: 12336

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.

Upvotes: 1

Views: 261

Answers (2)

Dexygen
Dexygen

Reputation: 12561

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

Upvotes: 1

brennie
brennie

Reputation: 543

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.)

Upvotes: 8

Related Questions