Skip to content

Instantly share code, notes, and snippets.

@neingeist
Created March 19, 2013 10:10
Show Gist options
  • Save neingeist/5194968 to your computer and use it in GitHub Desktop.
Save neingeist/5194968 to your computer and use it in GitHub Desktop.
Check PTR for every IP in the given block.
#!/usr/bin/perl
# Check PTR for every IP in the given block.
use 5.010;
use strict;
use warnings;
use Readonly;
use Net::Netmask;
use Socket;
Readonly my $BLOCK => '46.4.238.160/28';
my $block = Net::Netmask->new($BLOCK);
for my $ip ($block->enumerate()) {
my $ptr_name = gethostbyaddr inet_aton($ip), AF_INET;
my $ptr_ip = inet_ntoa(scalar gethostbyname $ptr_name);
if ($ip eq $ptr_ip) {
say "OK: $ip resolves to $ptr_name";
} else {
say "W: $ip resolves to $ptr_name and it does NOT resolve back, but to $ptr_ip instead.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment