#!/usr/bin/perl # Author: Augie Schwer # $Id: axfr2rbldnsd.pl 1274 2007-09-23 20:30:17Z augie $ # Purpose: Convert a transfered zone files to rbldnsd style and # prints to STDOUT. use strict; unless ( defined $ARGV[0] ) { print "USAGE : $0 zone_to_transfer (host)\n"; exit; } my $zone = $ARGV[0]; my $host = $ARGV[1] || 'localhost'; my $time = time(); my $tmp_file = "/tmp/$zone.$time"; my $found_ns = 0; my $found_soa = 0; `dig \@$host axfr $zone > $tmp_file`; open FILE , "$tmp_file" or die "Could not open $tmp_file : $!"; while () { # Ignore comments next if /^;/; # remove everything in front of SOA, but keep the TTL. if (!$found_soa) # we only need one SOA. { if ( /(\d+)\s+IN\s+SOA\s+(.+)$/ ) { print "\$SOA $1 $2"; $found_soa = 1; next; } } # remove everything in front of NS, but keep the TTL. # concat all NS records together. if (!$found_ns and /(\d+)\s+IN\s+NS\s+(.+)$/) { print "\n\$NS $1 $2 "; $found_ns = 1; next; } if ( /IN\s+NS\s+(.+)$/ ) { print "$1 "; next; } # anything that's not a sub-domain gets an '@' in # front followed by the type and record. if ( /^$zone\.\s+(\d+)\s+IN\s+(A|MX)\s+(.+)$/ ) { print "\n@ $1 $2 $3\n"; next; } # print the rest of the A records. if ( /^(.+)\.$zone\.\s+(\d+)\s+IN\s+A\s+(.+)$/ ) { print "$1 $2 IN A $3\n"; next; } } # clean up after myself. `rm -f $tmp_file`;