Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 17th, 2013  |  syntax: Perl  |  size: 1.02 KB  |  views: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. };
clone this paste RAW Paste Data