my %hosts; my $ip = qr/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/; while(my $line =<>){ chomp $line; if($line =~ m/for (.*)$/){ my @f = split /\s+/, $1; if(scalar(@f) == 1) { $hosts{$f[0]} = $f[0]; } else { $f[1] =~ s/\(//; $f[1] =~ s/\)//; $hosts{$f[1]} = $f[0]; }; }; }; foreach my $k(map substr($_, 4) => sort map pack('C4' => m/(\d+)\.(\d+)\.(\d+)\.(\d+)/) . $_ => keys(%hosts)) { my $v = $hosts{$k}; if($v =~ $ip) { print "$v is up\n"; } else { my $r = `host $v`; my @l = split /\n/, $r; my $resolve; foreach my $i(@l) { if($i =~ $ip) { my @f = reverse(split /\s+/, $i); $resolve = $f[0]; $resolve =~ s/\.$//; last; }; }; if($resolve) { print "$k is up, has PTR $v, " . ($resolve eq $k ? "forward for that name matches\n" : "but forward for that name resolves to $resolve\n"); } else { print "$k is up, has PTR $v, unable to resolve forward for that name\n"; }; }; };