Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
138 lines (114 sloc) 2.7 KB
#!/usr/bin/perl
###
### USAGE: perl jarf-rev 10.10.1.1-10.10.1.234
###
if (scalar @ARGV < 1) {die "perl jarf-rev 10.10.1.1-10.10.1.234 \r\n";}
use Parallel::ForkManager;
###
#Sub Routines
###
####
sub do_work{
my ($search)=@_;
@nslookupout=`nslookup -timeout=3 -retry=2 $search $ns 2>&1`;
foreach $line (@nslookupout){
if ($line =~ /Name:/){
($duh,$returner,@crap)=split(/Name: /,$line);
}
}
$returner=~s/ //g;
chomp $returner;
if ($mode==0){
$tosave=$returner.";".$search.";RL";
}
if ($mode==1){
$tosave=$returner.";".$search.";RL";
}
if ($mode==2){
$tosave=$returner.";".$search.";RL";
}
print "$tosave\n";
}
####
sub dedupe(@){return uniq map { lc $_ } @_;}
####
sub ip2long
{
my @ips = split (/\./, $_[0]);
my $binNum = "";
foreach $tuple (@ips) {
$binNum = $binNum.dec2bin($tuple);
}
$BigNum = bin2dec($binNum);
return ($BigNum);
}
####
sub dec2bin
{
my $str = unpack("B32", pack("N", shift));
$str =~ s/^0+(?=\d)//;
my $RetStr = "";
for ($i=0; $i< 8 - length($str); $i++) {
$RetStr=$RetStr."0";
}
$RetStr = $RetStr.$str;
return $RetStr;
}
####
sub bin2dec
{
return unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
}
####
sub long2ip
{
my $binNum = dec2bin($_[0]);
my $ipNum = "";
my $i;
my $ln;
if ( ($ln = length($binNum)) < 32) {
my $Pad = "";
for ($p=0; $p<32-$ln; $p++) {
$Pad.="0";
}
$binNum=$Pad.$binNum;
}
for ($i=0; $i<32; $i+=8) {
my $tuple = substr($binNum, $i, 8);
my $des = bin2dec($tuple);
if ($ipNum eq "") {
$ipNum = $ipNum.$des;
} else {
$ipNum = $ipNum.".".$des;
}
}
return ($ipNum);
}
###
#Main Program starts here
###
$|=1;
my $MAX_PROCESSES = 10;
my $pm=new Parallel::ForkManager($MAX_PROCESSES);
my $subnet=@ARGV[0];
my $ns=@ARGV[1];
my $mode=2;
##get the real length of the range
my ($StartIP, $StopIP) = split (/-/,$subnet);
my $Start=ip2long($StartIP);
my $Stop=ip2long($StopIP)+1;
my $Dif=$Stop-$Start;
if ($StartIP eq $StopIP){$Dif=1;}
## load it up
for (my $z=0; $z < $Dif; $z++) {
$Longval=$Start+$z;
$NewIP = long2ip($Longval);
push @stuff,$NewIP;
}
## fire away!
foreach $thing (@stuff){
my $pid = $pm->start("id: $thing") and next;
do_work($thing);
$pm->finish();
}
$pm->wait_all_children();