#!/usr/bin/perl -w $|=1; use strict; use Net::Ping; use Net::Netmask; use Net::DNS; use Getopt::Long; my @blocks=(); my $outfile=""; my $dns = Net::DNS::Resolver -> new; my $res = GetOptions("net=s",\@blocks, "out=s",\$outfile ); $outfile="candidates.txt" unless $outfile; @blocks=split(",",join(",",@blocks)); foreach my $i(0..$#blocks){ unless ($blocks[$i] =~ m@^\d+\.\d+\.\d+\.\d+/\d+$@){ $blocks[$i] = $blocks[$i] . "/24"; } } open FOUT,sprintf("> %s",$outfile) or die "$outfile: $!"; my $p = Net::Ping->new(); foreach my $block(@blocks){ my $net = Net::Netmask->new($block); foreach my $ip($net->enumerate()){ next if $ip =~ m@\.0$@; next if $dns->search($ip); printf "%s\r",$ip; unless ($p->ping($ip,1)){ printf FOUT "%s\n",$ip; } } }