Ping.pl

From wiki.perl.lt
Jump to: navigation, search
#!/usr/bin/perl
use strict;
# pings 3 times range of ip's f.e. 10.1.11.1-254
# cretes x.x.x.x.log with live ip's
# bug #1: does not filter entered ip.
# (c)-left algirdas
my $chkip=shift;
chomp($chkip);
  if ($chkip) {
    open(F,">$chkip\.log");
    for (my $nr=1; $nr<255; $nr++) {
      my $ip = $chkip;
      $ip =~ s/x/$nr/g;
      print "checking $ip .. ";
      if (`ping -c 3 $ip | grep received` =~ /[123]\ received/) {
        print "alive\n";
        print F "$ip\n";
      }
      else { print "dead\n"; }
    }
    close(F);
  }
  else { print "usage: ./$0 10.1.11.x\n" }
Personal tools
Categories