Hi Monks,

I was in need of looking on my network and finding out which computers are alive at which addresses (in other words, not only getting the IP addresses of alive computers, but also their name). I came up with this script:

use Net::Telnet; use strict; my $username = "standarduser"; my $passwd = "standardpass"; my $base = "10.20.16"; my $start = 0; my $end = 256; my $t = new Net::Telnet (Timeout => 1, Prompt => '/<.> $/', Errmode => 'return'); if (defined $ARGV[0]){ $start = $ARGV[0]; } if (defined $ARGV[1]){ $end = $ARGV[1]; } for (my $i=$start; $i<$end; $i++){ $t->close unless $i==$start; print "Trying $i\n"; next unless $t->open("$base.$i"); next unless $t->login($username, $passwd); my @lines = $t->cmd("pwd"); print "$base.$i => $lines[1]\n"; #next command prompt }

This code basically opens a connection, and asks for the 'pwd', ignoring that information, but looking at next line's prompt, which contains the mahcine name. The script works great if it finds computers that accept the login. It works fine on ones that do not accept the login (not everything on the network is the same). And it even works fine for the first time there is no computer at that address. However, the second time this happens, the script just hangs, waiting for something. I've looked at the dump_log, but found nothing there.

I feel like I am missing something. Please help. Thanks.


In reply to Net::Telnet hanging by gri6507

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.