# Create a list of all possible IP addresses within subnet open(ALLIP, ">allip.list") || die "Unable to create file: allip.list\n"; for ($i=0; $i<=20; $i++) { print ALLIP "$ip_subnet.$i\n"; } close(ALLIP); open(ALLIP, "allip.list") || die "Unable to open file: allip.list\n"; open(PINGALLIP, ">pingallip.list") || die "Unable to open file: pingallip.list"; while () { system("ping $_ >pingallip.list") && "Unable to create file: pingallip.l ist"; chomp; } close(ALLIP); close(PINGALLIP); open(OUTPUT, ">output.list"); open(PINGALLIP, "pingallip.list") || die "Unable to open file: pingallip.list"; my $line = 0; while () { chomp; if ($_ =~ m/is alive/) { $line++; last; } } close(PINGALLIP); if ($line) { print OUTPUT "$_\n"; } else { print "ERROR\n"; }