Advertisement
Guest User

Untitled

a guest
Jan 17th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.02 KB | None | 0 0
  1. my %hosts;
  2. my $ip = qr/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
  3. while(my $line =<>){
  4.   chomp $line;
  5.   if($line =~ m/for (.*)$/){
  6.     my @f = split /\s+/, $1;
  7.     if(scalar(@f) == 1) {
  8.       $hosts{$f[0]} = $f[0];
  9.     } else {
  10.       $f[1] =~ s/\(//; $f[1] =~ s/\)//;
  11.       $hosts{$f[1]} = $f[0];
  12.     };
  13.   };
  14. };
  15. foreach my $k(map substr($_, 4) => sort map pack('C4' => m/(\d+)\.(\d+)\.(\d+)\.(\d+)/) . $_ => keys(%hosts)) {
  16.   my $v = $hosts{$k};
  17.   if($v =~ $ip) {
  18.     print "$v is up\n";
  19.   } else {
  20.     my $r = `host $v`;
  21.     my @l = split /\n/, $r;
  22.     my $resolve;
  23.     foreach my $i(@l) {
  24.       if($i =~ $ip) {
  25.         my @f = reverse(split /\s+/, $i);
  26.         $resolve = $f[0];
  27.         $resolve =~ s/\.$//;
  28.         last;
  29.       };
  30.     };
  31.     if($resolve) {
  32.       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");
  33.     } else {
  34.       print "$k is up, has PTR $v, unable to resolve forward for that name\n";
  35.     };
  36.   };
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement