Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Using the Net::Telnet package to develop with telnet ,everything looks great, example:

#!/usr/bin/perl

use strict;

use Net::Telnet;

my $telnet=Net::Telnet->new(Timeout => 5,Prompt

=> '/.+>/',Host => "1.1.1.1");

$telnet->login('cisco','cisco');

my @res=$telnet->cmd('show version');

print @res;

But now, the story is, I'm not allowed to use any CPAN packages, just pure perl to implement the same function -- given the IP username and password, simple command and then return the result (like example shown above), and what's more, the perl script need run well in windows (activeperl) as well as in linux.

Thanks for any help in advance ^_^

Replies are listed 'Best First'.
Re: perl+telnet(with out Net::Telnet)
by marto (Cardinal) on Jul 14, 2010 at 10:16 UTC
Re: perl+telnet(with out Net::Telnet)
by rovf (Priest) on Jul 14, 2010 at 10:51 UTC
    I'm not allowed to use any CPAN packages
    First, Net::Telnet is part of the Perl core (unless you are using a very old version), so it is pure Perl. Secondly, if you are not permitted to include separated modules into your application, you can just steal the code from CPAN and paste it into your code.

    Maybe you should put on top of this code the comment:

    # Message to my supervisor: No, I did not steal this # code from CPAN. Oh no, this is not something I would # ever dare to do.

    -- 
    Ronald Fischer <ynnor@mm.st>

      "First, Net::Telnet is part of the Perl core"

      I don't think it is: Core modules (n). See also perlfaq8 - Can I use perl to run a telnet or ftp session?:

      "Try the Net::FTP, TCP::Client, and Net::Telnet modules (available from CPAN). http://www.cpan.org/scripts/netstuff/telnet.emul.shar will also help for emulating the telnet protocol, but Net::Telnet is quite probably easier to use...."

        I don't think it is: Core modules.
        Indeed, this is strange. I first checked with Cygwin perl (5.10.0) and our Perl on Linux (5.10.1) and got the following pathes to Net::Telnet:

        /usr/lib/perl5/vendor_perl/5.10/Net/Telnet.pm /opt/perl_5.10.1/lib/Net/Telnet.pm
        But when I checked ActiveState Perl 5.10.0 on Windows, Net::Telnet was not included.

        -- 
        Ronald Fischer <ynnor@mm.st>