NAME

Parse::DNS::Zone - DNS Zone File Parser

SYNOPSIS

use Parse::DNS::Zone;

my $zone = Parse::DNS::Zone->new(
	zonefile=>'db.example',
	origin=>'example.org.',
);

my $a_rr = $zone->get_rdata(name=>'foo', rr=>'A');
my $mx_rr = $zone->get_rdata(name=>'@', rr=>'MX'); # Get the origin's MX

# Get SOA values
my $mname = $zone->get_mname();
my $rname = $zone->get_rname();
my $serial = $zone->get_serial();
# ... etc ...

DESCRIPTION

Parse::DNS::Zone parses a zonefile, used to define a DNS Zone and gives you the information therein, via an object oriented interface. Parse::DNS::Zone doesn't validate rrdata, except for SOA, and is used to 1) validate the basic structure of the file and 2) extract rdata so you can parse it and validate it yourself.

Parse::DNS::Zone supports RFC 1034 zones:

  • $INCLUDE

  • $TTL

  • $ORIGIN

Parse::DNS::Zone does not support $GENERATE in this version.

CONSTRUCTOR

Parse::DNS::Zone->new( ARGS )

Required Arguments
  • origin

    Origin

  • zonefile

    Path to the zonefile being parsed

Optional Arguments
  • require_soa

    If set to a value other than 0, the parser will whine and die if the zonefile doesn't contain a SOA record. (Default: yes)

METHODS

General

$zone->get_rdata(name=>$name, rr=>$rr, n=>$n, field=>$field)

Is used to get the data associated with a specific name and rr type. The $name can be as the name appears in the zonefile, or a fqdn (with trailing .) as long as it is tracked by the zonefile. For multiple RRs for a name, you can specify a $n argument to get a specific data set. Default is 0, so if you only have one, you don't need to specify this.

The $field is the particular component of the resource record to return. It defaults to 'val', which is the actual value of the record. Other possibilities are 'class' (e.g. "IN") and 'ttl'.

$zone->exists($name)

Returns a true value if the name exists, and false otherwise.

$zone->get_rrs($name)

Returns a list with all RR types for a specific name

$zone->get_dupes(name=>$name, rr=>$rr)

Returns how many RRs of a given type is defined for $name. For a simple setup with a single RR for $name, this will return 1. If you have some kind of load balancing or other scheme using mutiple RRs of the same type this sub will return the number of "dupes".

$zone->get_names( )

Returns a list with all names specified in the zone

SOA

$zone->get_mname( )

Returns the MNAME part of the SOA.

$zone->get_rname( parse=>{0,1} )

Return the RNAME part of the SOA. If parse is set to a value other than 0, the value will be interpreted to show an emailaddress. (default: 0)

$zone->get_serial( )

Return the SERIAL value of a SOA.

$zone->get_refresh( )

Return the REFRESH value of a SOA

$zone->get_retry( )

Return the RETRY value of a SOA

$zone->get_expire( )

Return the EXPIRE value of a SOA

$zone->get_minimum( )

Return the MINIMUM value of a SOA

SEE ALSO

RFC 1034, RFC 1035, Bind Administrator's Guide

COPYRIGHT

Copyright (c) 2009, 2010 - Olof Johansson <zibri@cpan.org>. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.