Here is a Perl Script that I wrote to convert reverse DNS Zone Files from Windows to something that can be used by Bind on Unix. It creates a new Unix zone file for each Windows dns file and a named.conf.windows file (to put into your named.conf file on Unix) and a named.slave.inc.windows file (to put into named.slave.inc or named.slave.conf file on Unix).
#!/usr/bin/perl -w
# Author: John Scipione @ Netsville (http://www.netsville.com)
# This script converts reverse zone files found in
# %SystemRoot%\System32\dns on a Windows server to ones that can
# be used by Bind on a Unix server.
use strict;
my $primarydns = ''; # Hostname of your primary DNS server (w/o trailing .)
my $primarydnsip = ''; # IP of your primary DNS server
my $rootname = ''; # Domain Contact Root Name
my $secondarydns = ''; # Hostname of your secondary DNS server (w/o trailing .)
my $refresh = '3600';
my $retry = '600';
my $expire = '604800';
my $ttl = '3600'; # Minimum TTL
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$year += 1900; # Perl uses years since 1900 by default
$mon = sprintf("%02d", $mon + 1); # Perl uses month [0..11] by default
$mday = sprintf("%02d", $mday);
open(MASTER, '>', 'named.conf.windows'); # blank file out
close(MASTER);
open(SLAVE, '>', 'named.slave.inc.windows'); # blank file out
close(SLAVE);
my @files = <*>;
foreach my $file (@files) {
if (substr($file, -3) ne 'dns') {
next; # skip if file does not end in .dns
}
my $outfilename = substr($file, 0, -3) . 'zone';
my @pieces = split(/\./, $file);
my $third_octet = $pieces[0];
my $classB = $pieces[1] . '.' . $pieces[2];
my $classC = $pieces[0] . '.' . $pieces[1] . '.' . $pieces[2];
open(INFH, '<', $file);
open(OUTFH, '>', $outfilename);
print OUTFH "\$TTL $ttl\n";
print OUTFH "\$ORIGIN $classB.in-addr.arpa.\n";
print OUTFH "$third_octet\tIN\tSOA $primarydns. $rootname. (\n";
print OUTFH "\t\t\t\t\t\t" . $year . $mon . $mday . "00\t; serial number\n";
print OUTFH "\t\t\t\t\t\t$refresh\t\t; refresh\n";
print OUTFH "\t\t\t\t\t\t$retry\t\t\t; retry\n";
print OUTFH "\t\t\t\t\t\t$expire\t\t; expire\n";
print OUTFH "\t\t\t\t\t\t$ttl )\t\t; default ttl\n\n";
print OUTFH "\tIN\tNS\t$primarydns.\n";
print OUTFH "\tIN\tNS\t$secondarydns.\n\n";
print OUTFH "\$ORIGIN $classC.in-addr.arpa.\n";
while (<INFH>) {
if (substr($_, 0, 1) eq ';') {
next; # skip comment lines
}
$_ =~ s/\r//g; # trim off \r
if ($_ =~ /(\d+)\s+PTR\s+(\S+\.\S+\.\S+\.)/) {
print OUTFH "$1\tIN\tPTR\t$2\n";
} elsif ($_ =~ /\s+PTR\s+(\S+\.\S+\.\S+\.)/) {
print OUTFH "\tIN\tPTR\t$1\n";
}
}
close(INFH);
close(OUTFH);
open(MASTER, '>>', "named.conf.windows");
print MASTER "zone \"$classC.in-addr.arpa\" {\n";
print MASTER " type master;\n";
print MASTER " file \"$classC.in-addr.arpa.zone\";\n";
print MASTER "};\n";
close(MASTER);
open(SLAVE, '>>', "named.slave.inc.windows");
print SLAVE "zone \"$classC.in-addr.arpa\" {\n";
print SLAVE " type slave;\n";
print SLAVE " file \"$classC.in-addr.arpa.bak\";\n";
print SLAVE " masters { $primarydnsip; };\n";
print SLAVE "};\n";
close(SLAVE);
}