Hi all !,
I have this nice script that was created by someone else. and was looking for a different opinions on this forum.
Code :
#!perl -w
use strict;
my %all_ips;
my %all_zones;
my %zone_ips;
while (<>) {
next unless /^zone\s+\"(.*)\"/;
my $zone = $1;
while (<>) {
print "Warn: allow-update not found in $zone\n" if /^\}\;/;
next unless /allow-update\s*\{\s*(.*)/;
my $ips = $1;
if ($ips =~ /none/i) {
print "Warn: zone $zone contains no IPs (none)\n";
last;
}
while (<>) {
if (/(.*)\}\;/) {
$ips .= $1;
if ($ips =~ /none/i) {
print "Warn: $zone contains no IPs (none)\n";
last;
}
my %seen;
my @ips = grep {!$seen{$_}++} split(/[\s\;]+/, $ips);
foreach (@ips) {
$all_ips{$_}++;
$zone_ips{$_} .= " $zone";
}
$all_zones{$zone} = [ @ips ];
last;
}
$ips .= $_;
}
last;
}
}
my $num_zones = keys(%all_zones);
print "\nCounted ".$num_zones." zones.\n";
exit unless $num_zones;
print "\nThey are:\n";
print join("\n", keys %all_zones)."\n";
my @in_all;
my @not_all;
foreach (sort keys %all_ips) {
if ($all_ips{$_}==$num_zones) {
push @in_all, $_;
}
else {
push @not_all, $_;
}
}
if (@in_all) {
print "\nThe following IP's appear in all $num_zones zones:\n";
print join("\n", @in_all)."\n";
}
if (@not_all) {
print "\nThe following IP's do not appear in all zones:\n";
print "\nIP shown with zones it's found in:\n";
foreach (@not_all) {
print $_." $zone_ips{$_}\n";
}
}
But the output is not quite what I need: right now it looks like this: ( keep in mind this is not the entire output, just an excerpt.
Warn: allow-update not found in qa.sarkie.net
Warn: zone dhcp.sark.com contains no IPs (none)
Warn: allow-update not found in 127.in-addr.arpa
Counted 4 zones.
They are:
wes.sark.com
fre.sark.com
nrm.sark.com
us.ad.sark.com
The following IP's appear in all 4 zones:
10.128.1.54
133.180.204.54
133.180.204.55
133.85.117.224
IP's shown with zones it's found in:
10.128.1.53 sarkie.com aus.sarkie.com col.sarkie.com dal.sarkie.com wes.sarkie.com wil.sarkie.com wilm.sarkie.com us.ad.sarkie.com qa.richard.net spr.sarkie.com htr.sarkie.com nor.sarkie.com nrm.sarkie.com elg.sarkie.com fdr.sarkie.com ven.sarkie.com ext.sarkie.com fre.sarkie.com car.sarkie.com het.sarkie.com heathrow.sarkie.com cha.sarkie.com net.sarkie.com lvs.sarkie.com tst.ad.sarkie.com mec.sarkie.com 127.in-addr.arpa 168.in-addr.arpa 192.in-addr.arpa
10.128.2.53 sarkie.com aus.sarkie.com col.sarkie.com dal.sarkie.com wes.sarkie.com wil.sarkie.com wilm.sarkie.com us.ad.sarkie.com qa.richard.net spr.sarkie.com htr.sarkie.com nor.sarkie.com nrm.sarkie.com elg.sarkie.com fdr.sarkie.com ven.sarkie.com ext.sarkie.com fre.sarkie.com car.sarkie.com het.sarkie.com heathrow.sarkie.com cha.sarkie.com net.sarkie.com lvs.sarkie.com tst.ad.sarkie.com mec.sarkie.com 127.in-addr.arpa 168.in-addr.arpa 192.in-addr.arpa
10.144.1.53 sarkie.com aus.sarkie.com col.sarkie.com dal.sarkie.com wes.sarkie.com wil.sarkie.com wilm.sarkie.com us.ad.sarkie.com qa.richard.net spr.sarkie.com htr.sarkie.com nor.sarkie.com nrm.sarkie.com elg.sarkie.com fdr.sarkie.com ven.sarkie.com ext.sarkie.com fre.sarkie.com car.sarkie.com het.sarkie.com heathrow.sarkie.com cha.sarkie.com net.sarkie.com lvs.sarkie.com tst.ad.sarkie.com mec.sarkie.com 127.in-addr.arpa 168.in-addr.arpa 192.in-addr.arpa
Its still hard to pinpoint what IP's and zones go to what.
so, this is my thought on a better output
Lets say I have these zones which the scripts finds just fine
ad.sark123.com
aus.rich.com
sark.com
under each zone we have allow-update with many IP addresses
What I need to do is find out if any or all of the IP's are the same in each zone or not.
So my thinking is to have a report like so
from the 30 zones found, all these zones ZYZ.. have the same IP addresses except for zones XYZ. The zone are..., and the IP addresses are...
Could someone help me tweak this to make it a lot easier to figure out what zones have the same IP's and what zones do not as per my example above.
Also, the master file this is run against is below: ( just an excerpt)
I have a named.conf file that looks like this, small excerpt of the real file)
Code :
controls {
inet 127.0.0.1 allow { localhost; } keys { "rndc-key"; };
};
key "rndc-key" {
algorithm "hdtc-m65";
secret "helpme=";
};
acl "SRS" {
121.118.14.107;
187.118.215.112;
153.118.255.200;
};
acl "SRSHUTYDNS" {
200.180.12.100;
100.200.138.82;
190.121.100.68;
30.129.21.81;
};
options {
directory "/var2/named";
qddns
{
edup
{
my-ip 200.118.14.102;
message-service-ip 127.0.0.1;
message-service-port 4468;
org-id 200;
};
};
forwarders {
120.180.238.53; // SRS5
120.180.174.53; // SRS4
120.180.254.53; // SRSdns6
};
forward only;
minimal-responses yes;
allow-transfer { "SRSCARD"; "SRSHUTYDNS"; }; // test
allow-query { any; };
notify yes;
version "";
};
logging {
channel xfer_info {
file "log/xfer.log" versions 5 size 5m;
print-time yes;
print-severity yes;
severity info;
};
category xfer-in {xfer_info;};
category xfer-out {xfer_info;};
};
#include "db.INCLUDE.logging.query";
include "db.INCLUDE.forwarders-for-sark";
zone "sark.com" in {
type master;
file "db.sark.com";
allow-update { 211.118.95.190;211.118.66.65;211.118.49.164;211.118.4.246;211.118.4.165;211.118.4.162;
211.118.255.102;211.118.246.12;211.118.215.102;211.118.212.210;211.118.19.190;211.118.19.102;
211.118.14.8;211.118.14.102;211.118.116.198;167.85.70.12;167.85.16.154;167.85.117.224;12.128.1.54;
120.180.204.54;120.180.204.55;211.118.31.229; 167.85.102.1; 167.85.102.2;120.180.254.55;120.180.254.54;
12.128.1.53;12.128.2.53;12.144.1.53;12.144.2.53;12.148.1.53;12.148.2.53;
12.160.1.53;12.160.2.53;199.86.40.148;199.86.40.20;199.86.40.220;199.86.40.28;
199.86.40.36;199.86.40.68;199.86.40.76;199.86.40.84;
};
};
zone "ad.sark123.com" in {
type master;
file "db.ad.sark123.com";
allow-update { 211.118.95.190;211.118.66.65;211.118.49.164;211.118.4.246;211.118.4.165;211.118.4.162;
211.118.255.102;211.118.246.12;211.118.215.102;211.118.212.210;211.118.19.190;211.118.19.102;
211.118.14.8;211.118.14.102;211.118.116.198;167.85.70.12;167.85.16.154;167.85.117.224;12.128.1.54;
120.180.204.54;120.180.204.55;211.118.31.229;120.180.254.55;120.180.254.54;
};
zddns
{
edup rr-types { "A"; "CNAME"; "PTR"; "SRV"; };
};
};
zone "aus.rich.com" in {
type master;
file "db.aus.rich.com";
allow-update { 211.118.95.190;211.118.66.65;211.118.49.164;211.118.4.246;211.118.4.165;211.118.4.162;
211.118.255.102;211.118.246.12;211.118.215.102;211.118.212.210;211.118.19.190;211.118.19.102;
211.118.14.8;211.118.14.102;211.118.116.198;167.85.70.12;167.85.16.154;167.85.117.224;12.128.1.54;
120.180.204.54;120.180.204.55;211.118.31.229;120.180.254.55;120.180.254.54;
12.128.1.53;12.128.2.53;12.144.1.53;12.144.2.53;12.148.1.53;12.148.2.53;
12.160.1.53;12.160.2.53;199.86.40.148;199.86.40.20;199.86.40.220;199.86.40.28;
199.86.40.36;199.86.40.68;199.86.40.76;199.86.40.84;
};
};