#!/usr/bin/perl -w use strict; my $ip; my $goodhosts = 0; my $marker = 0; while ($goodhosts != 10 ) { #used to pick a random ip address open(GETHOST, "nmap -iR 1 -sL |") || die "fix your code\n"; while () { chomp; if ($_ =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) { $ip = $1; } } close(GETHOST); #test for idleness open(IDLERESULT, "nmap -P0 -sI $ip whatever.ip |") || die "bad code\n"; while () { chomp; if (m/completed/) { $marker = 1; } } close(IDLERESULT); if ($marker == 1) { $goodhosts = $goodhosts + 1; system("echo $ip >> idle_hosts"); $marker = 0; } }