#!/usr/bin/perl use strict; use warnings; use File::Find; use FileHandle; use Data::Dumper; use Net::DNS::ZoneFile; use DBI; my $dbh = DBI->connect( "DBI:mysql:database=dns;host=localhost", "root", "test", {'RaiseError' => 1} ); my $sth = $dbh->prepare( "INSERT INTO a (hname,zone,host) VALUES (?,?,?)" ); my $base = "/chroot/named/master/net"; find(\&wanted, $base); $dbh->disconnect(); exit; sub wanted { return unless ( -f "$File::Find::name" and $File::Find::name !~ m! /in-addr/! ); my $index = 1; my $root = shift; my $zone = new FileHandle "$File::Find::name", "r"; my @name = split('/',$File::Find::name); my $out = join('.', reverse(@name[4..$#name])); my $rrset = Net::DNS::ZoneFile->readfh($zone, $root); for(@$rrset) { print "This is our file to be parsed $out\n"; print "Working on line: ", $index++, ".\n"; print "$_->{type}\n"; print "$_->rdatastr\n" if $_->{type} =~ m/^A/; print "$_->{name},",$_->rdatastr, "\n" if $_->{type} =~ m/^A/; print STDOUT Data::Dumper->Dump([$_->rrset]) . "\n"; if($_->{type} =~ m/^A/) { print "Working on line: ", $index++, ".\n"; $sth->execute( $_->{name}, $out, $_->rdatastr) or die $dbh->errstr; } } }