derek3000 has asked for the wisdom of the Perl Monks concerning the following question:
Hi. I'm writing a little batch pinging utility that asks for the third octet and then scans the fourth from 1-255. I want the ping results to go to a log file, and then to scan that log file for a line containing "x bytes from 10.32.z.y" so that i know that ip is taken. The code is below. First though, I want to make sure my problems are clear:
1. It prints nothing to "ips.txt", even though ping fills out "log.txt" fine.
2. Styllistically, I want any suggestions to make the code more idiomatic.
any help would be much appreciated. Thanks, Derek---------------------------------------------------------------------- +----- #!/usr/bin/perl -w use strict; print "Please enter the third octet for scannin': "; my $octet3 = <>; chomp $octet3; open(LOG, ">log.txt") || die "Couldn't open log file: $! \n"; for(my $x = 0; $x < 20; $x++){ open(PINGIN, "ping 10.32.$octet3.$x -w 5 |") or die "Couldn't pull that one off: $! \n"; while(<PINGIN>){ warn "Logging activity for 10.32.$octet3.$x \n"; print LOG $_; } } close PINGIN; close LOG; open(LOG, "log.txt") or die "$!"; open(UNAVAILABLE, ">ips.txt") or die "$!"; while(my $line = <LOG>){ if($line =~ /^64 bytes from ([0-9.]):/){ my $ip = $1; print UNAVAILABLE "$ip is unavailable.\n"; } } close LOG; close AVAILABLE; --------------------------------------------------------------------
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: batch ping problem
by marcink (Monk) on Jun 13, 2001 at 19:18 UTC | |
Re: batch ping problem
by Henri Icarus (Beadle) on Jun 13, 2001 at 19:27 UTC | |
Re: batch ping problem
by derek3000 (Beadle) on Jun 13, 2001 at 19:40 UTC | |
Re: batch ping problem
by Anonymous Monk on Jun 13, 2001 at 22:54 UTC |
Back to
Seekers of Perl Wisdom