Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Net::Telnet

by Rex(Wrecks) (Curate)
on Apr 04, 2002 at 20:05 UTC ( #156748=modulereview: print w/ replies, xml ) Need Help??

Item Description: Making telnet with perl way too easy.

Review Synopsis:

Overview


Net::Telnet is a very easy to use module for most tasks requiring telnet. It has an OO type interface that works very well for what I have used it for and it crosses platforms easily.

The Meat

I haven't actually gone through the code enough to do a review on the actual code, but what I have seen is well written and easy to follow. There are extensive help pages that are also well written and easy to follow.

I have used this module successfully on both FreeBSD and Win2k with only one glitch (see below). I have used it with great success in child processes on FreeBSD as well as "compiled" it into a freestanding .exe for Win2k. Everything worked great "out of the box" and there was only one wrinkle to iron out.

I've used it connecting to several different devices including Cisco 2511 comm servers, Cisco switches and routers (CatOS and IOS), Foundry switches, Nokia IPXXX and Nokia CCXXX boxes. All worked great with the exception of a few tweaks required for the Cisco comm servers. I have also used it for Telnet access to FreeBSD machines for remote control purposes and it handles this very well.

Update: First, thanks to rob_au for the fix below and Second, I updated some of the text.
Update 2: There is a new version (3.03) of Net::Telnet on CPAN now and the author has *fixed* the issue above. I'm not sure if I like the fix (local $^W = '';), but it will now work without warnings. I did inform the author of the fixes below, however he may have reasons for discarding them and using his method. I don't know what that would be, but there may be something I'm not seeing.

The bugs


Note: These bugs are in relation to the 3.02 version of this module.
I did find a couple things worth mentioning.
  • A bug when running in a script with -w when on a Win2k platform, I traced down the warning to a > comparision, but was not able to fix it for some reason. Seems like it may be an ActiveState bug, but I have not debugged it further...YET! The workaround I used is in this code:
    my $telnetObj = new Net::Telnet (Timeout => 20, Prompt => '/[^ <-]\>/' +, Errmode => "return") ; my $tmp = $^W ; local($^W) = 0; $telnetObj->open(Host => $gw_in_addr) ; #offending code in here $^W = $tmp;
  • The author was not responsive to this issue at all.
  • The other issue was a sync problem with the Cisco comm server. however I found that feeding a known bogus command and junking the output would usually sync me back up.

    Conclusion


    It beats anything else out there. It has a great interface and I find it works much easier than expect for small jobs. The fact that it "compiles" into a freestanding .exe in Win2k, and works in child processes also attests to the stability in my mind.

    If you need telnet...Net::Telnet is the only way to do it via perl.

    Comment on Net::Telnet
    Select or Download Code
    Re: Net::Telnet
    by rob_au (Abbot) on Apr 04, 2002 at 23:36 UTC
      This is a good review of Net::Telnet - I was interested in the bug-report and the problem which you found executing code under -w and so decided to do a little digging.

      The problem which you encountered can be replicated on ActiveState Perl build 630 with the following line:

      >C:\>perl -MNet::Telnet -w -e "$obj = Net::Telnet->new; $obj->open(Hos +t => '127.0.0.1');" Argument "" isn't numeric in numeric gt (>) at C:/Perl/site/lib/Net/Te +lnet.pm line 2569.

      The problem lies in the _optimal_blksize method of the Telnet.pm module and is not related to ActiveState per se, but the manner by which this method is called from within the new initiation method. The code for the _optimal_blksize method is as follows:

      sub _optimal_blksize { my ($blksize) = @_; return $blksize if defined $blksize and $blksize > 0 and $blksize <= 1_048_576; 8192; } # end sub _optimal_blksize

      This method is called without any parameters from the Net::Telnet new method and as such the variable $blksize will be undefined. This rightly generates the warning in the return $blksize if defined $blksize and ... line. This is expected behaviour under -w.

      A straight-forward fix for this problem under -w execution can be applied by adding the line:

      sub _optimal_blksize { my ($blksize) = @_; $blksize ||= 0; return $blksize if defined $blksize and $blksize > 0 and $blksize <= 1_048_576; 8192; } # end sub _optimal_blksize

      ... which can be applied as the following diff patch ...

      2568d2567 < $blksize ||= 0;

      As an aside note, I tested and was unable to replicate this warning with similarly versioned copies of Net::Telnet on Perl 5.6.1 on a i686-Linux system. Perhaps there is something more to this or the way by which warnings are generated?

       

        A simpler fix would have been to simply remove the "defined"
        sub _optimal_blksize { my ($blksize) = @_; return $blksize if $blksize and $blksize > 0 and $blksize <= 1_048 +_576; 8192; } # end sub _optimal_blksize
        ;-)

        UPDATE: I put the >0 test back in, to remove the rope that might hang someone trying to use a negative size...

        Yves / DeMerphq
        ---
        Writing a good benchmark isnt as easy as it might look.

    Back to Reviews

  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: modulereview [id://156748]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (5)
    As of 2014-07-12 00:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (238 votes), past polls