Both forward and reverse zones are listed. I use it for verify my configuration. On the reverse zone it shows the mask used.
#!/usr/bin/perl
use strict;
use Socket;
use Getopt::Std;
my $domain = 'infra.gvt.net.br';
my @devices;
my @list;
while (<>) {
chop;
if ( /^sysName:(.*)/ ) {
if ($#list > 0) {
my @tmp = @list;
push @devices, \@tmp;
}
@list = ( $1 );
} elsif ( /^isRouter:(.*)/ ) {
$list[1] = $1;
} elsif ( /^managedAddress:(.*)/ ) {
$list[2] = $1;
} elsif ( /^IP:([\d\.]+)\/([\d\.]+)/ ) {
push @{$list[3]}, [ $1, $2 ];
} elsif ( /^NH:([\d\.]+)/ ) {
push @{$list[4]}, $1;
}
}
push @devices, \@list if ($#list > 0);
sub calcNetwork {
my ($ipAddress, $netmask) = @_;
my @ipOct = split(/\./, $ipAddress);
my @maskOct = split(/\./, $netmask);
return join('.', map { int $ipOct[$_] & int $maskOct[$_] } (0..3));
}
my %ipAddresses;
my %sysNames;
my %networks;
for (@devices) {
my ($sysName, $ipForwarding, $managedAddress) = @{$_};
push @{$sysNames{$sysName}}, $managedAddress;
foreach my $ip (@{$_->[3]}) {
push @{$ipAddresses{$ip->[0]}{sysname}}, $sysName;
push @{$ipAddresses{$ip->[0]}{netmask}}, $ip->[1] unless (grep { $ip->[1] } @{$ipAddresses{$ip->[0]}{netmask}});
}
}
foreach my $sysName (keys %sysNames) {
my $addr = gethostbyname($sysName);
$addr = defined $addr ? inet_ntoa($addr) : '';
my ($name) = $sysName =~ /\./ ? $sysName =~ /^(.*?)\..*$/ : ($sysName);
print lc("$name.$domain"), "\t($addr)\t", $sysNames{$sysName}[0], "\n";
}
foreach my $ipAddress (sort keys %ipAddresses) {
my $addr = gethostbyaddr(inet_aton($ipAddress), AF_INET);
my $network = &calcNetwork($ipAddress, $ipAddresses{$ipAddress}{netmask}[0]);
print "$ipAddress\t($addr)\t$network/", $ipAddresses{$ipAddress}{netmask}[0], " ",
join(', ', map { lc "$_.$domain" } map { $_ =~ /\./ ? $_ =~ /^(.*?)\..*$/ : $_ } @{$ipAddresses{$ipAddress}{sysname}}), "\n";
}