| 1 |
use Net::IP; |
| 2 |
|
| 3 |
@ns=(':ns.nerxs.com',':ns.dorsch.org',':ns.c0re.jp'); |
| 4 |
|
| 5 |
print "\n# domains\n"; |
| 6 |
|
| 7 |
open(IN, '<domains'); |
| 8 |
|
| 9 |
while(<IN>) |
| 10 |
{ |
| 11 |
if(!/^#/) |
| 12 |
{ |
| 13 |
s/\n//; |
| 14 |
($domain, $owner) = split(/:/); |
| 15 |
print ("'$domain:Contact for this domain is $owner\n"); |
| 16 |
foreach (@ns) |
| 17 |
{ |
| 18 |
print (".".$domain.":$_\n"); |
| 19 |
} |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
print "\n# networks\n"; |
| 25 |
|
| 26 |
open(IN, '<networks'); |
| 27 |
|
| 28 |
while(<IN>) |
| 29 |
{ |
| 30 |
|
| 31 |
if(!/^#/) |
| 32 |
{ |
| 33 |
s/\n//; |
| 34 |
print "# $_\n"; |
| 35 |
@nets = split(/,/); |
| 36 |
$name = shift @nets; |
| 37 |
foreach(@nets) |
| 38 |
{ |
| 39 |
my $ip = new Net::IP($_) or die (Net::IP::Error()); |
| 40 |
$net=$ip->ip(); |
| 41 |
$last=$ip->last_ip(); |
| 42 |
$net =~ s/://g; |
| 43 |
$last =~ s/://g; |
| 44 |
|
| 45 |
if($ip->size() > 32) |
| 46 |
{ |
| 47 |
foreach (@ns) |
| 48 |
{ |
| 49 |
print (".".$ip->reverse_ip().":$_\n"); |
| 50 |
} |
| 51 |
$ip6map{$ip->ip()} = $name; |
| 52 |
} |
| 53 |
else |
| 54 |
{ |
| 55 |
for($i = int($ip->intip()) + 1; $i < int($ip->intip()) + int($ip->size()); $i++) |
| 56 |
{ |
| 57 |
$nmap{sprintf("%d.%d.%d.%d", ($i >> 24) & 0xff, ($i >> 16) & 0xff, ($i>>8) & 0xff, $i & 0xff)} = "$name"; |
| 58 |
$rmap{sprintf("%d.%d.%d.%d", ($i >> 24) & 0xff, ($i >> 16) & 0xff, ($i>>8) & 0xff, $i & 0xff)} = $ip->binip(). ".$name"; |
| 59 |
} |
| 60 |
} |
| 61 |
print ("=net.$name:".$net."\n"); |
| 62 |
print ("=broadcast.$name:".$last."\n"); |
| 63 |
#print ("Bin : ".$ip->binip()."\n"); |
| 64 |
#print ("Mask: ".$ip->mask()."\n"); |
| 65 |
#print ("Size: ".$ip->size()."\n"); |
| 66 |
#print ("Type: ".$ip->iptype()."\n"); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
close(IN); |
| 72 |
|
| 73 |
print "\n# hosts\n"; |
| 74 |
|
| 75 |
open(IN, '<hosts'); |
| 76 |
|
| 77 |
while(<IN>) |
| 78 |
{ |
| 79 |
s/\n//; |
| 80 |
if(!/^#/) |
| 81 |
{ |
| 82 |
if(!/^-/) |
| 83 |
{ |
| 84 |
if(/^=/ || /^\+/) |
| 85 |
{ |
| 86 |
@i = split(':'); |
| 87 |
$rmap{$i[1]} = ''; |
| 88 |
} |
| 89 |
print "$_\n"; |
| 90 |
} |
| 91 |
else |
| 92 |
{ |
| 93 |
@fields = split(/\|/); |
| 94 |
$name = shift(@fields); |
| 95 |
$name =~ s/^.(.)/$1/; |
| 96 |
$_ = shift(@fields); |
| 97 |
@ips = split(/,/); |
| 98 |
$_ = shift(@fields); |
| 99 |
@aliases = split(/,/); |
| 100 |
$admin = shift(@fields); |
| 101 |
if(!$admin) |
| 102 |
{ |
| 103 |
$admin = '[email protected]'; |
| 104 |
} |
| 105 |
$_ = shift(@fields); |
| 106 |
@mxes = split(/,/); |
| 107 |
foreach(@ips) |
| 108 |
{ |
| 109 |
my $ip = new Net::IP($_) or die (Net::IP::Error()); |
| 110 |
if(length($ip->binip()) == 32) |
| 111 |
{ |
| 112 |
# IPv4 is easy |
| 113 |
if(!$nmap{$_}) |
| 114 |
{ |
| 115 |
print STDERR "*** warning: no network for $_ ($name) - ignoring\n"; |
| 116 |
print "# no network for $_ ($name) - ignoring\n"; |
| 117 |
} |
| 118 |
else |
| 119 |
{ |
| 120 |
print "=$name." . $nmap{$_} . ":$_\n"; |
| 121 |
$rmap{$_} = ''; |
| 122 |
print "'$name." . $nmap{$_} . ":Host contact is $admin\n"; |
| 123 |
} |
| 124 |
foreach(@aliases) |
| 125 |
{ |
| 126 |
print "+$_:".$ip->ip()."\n"; |
| 127 |
print "'$_:Host contact is $admin\n"; |
| 128 |
} |
| 129 |
} |
| 130 |
else |
| 131 |
{ |
| 132 |
#IPv6 here |
| 133 |
$net = $ip->ip(); |
| 134 |
$net =~ s/^(....:....:....:....).*/$1:0000:0000:0000:0000/; |
| 135 |
if(!$ip6map{$net}) |
| 136 |
{ |
| 137 |
print STDERR "*** warning: no network for $_ ($name) - ignoring\n"; |
| 138 |
print "# no network for $_ ($name) - ignoring\n"; |
| 139 |
} |
| 140 |
else |
| 141 |
{ |
| 142 |
$rip = $ip->ip(); |
| 143 |
$rip =~ s/://g; |
| 144 |
print "6$name." . $ip6map{$net} . ":".$rip."\n"; |
| 145 |
} |
| 146 |
foreach(@aliases) |
| 147 |
{ |
| 148 |
$rip = $ip->ip(); |
| 149 |
$rip =~ s/://g; |
| 150 |
print "3$_:".$rip."\n"; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
close(IN); |
| 160 |
|
| 161 |
|
| 162 |
print "\n# reverse lookup\n"; |
| 163 |
foreach(sort(keys(%nmap))) |
| 164 |
{ |
| 165 |
if($rmap{$_}) |
| 166 |
{ |
| 167 |
print "=".$rmap{$_}.":$_\n"; |
| 168 |
} |
| 169 |
} |