gri6507 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Telnet hanging
by sweetblood (Prior) on Aug 21, 2003 at 15:45 UTC | |
by gri6507 (Deacon) on Aug 21, 2003 at 17:32 UTC |