Created
November 1, 2010 14:32
-
-
Save eiro/658253 to your computer and use it in GitHub Desktop.
parsing DNS zone with regexp::grammars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use Modern::Perl; | |
use YAML; | |
# Net::Grammars::Digzone; | |
# possible bugs: no empty line available | |
# http://en.wikipedia.org/wiki/List_of_DNS_record_types | |
my $parse_dig_zone = do { | |
use Regexp::Grammars; | |
qr{ | |
\A (?: <[record]> | |
| <.comment=(?: [;][^\n]+\n )> | |
)+ | |
\z | |
<rule:record> | |
<simplerecord> | |
| <srvrecord> | |
| <soarecord> | |
| <txtrecord> | |
# http://en.wikipedia.org/wiki/SRV_record#Record_format | |
<rule:srvrecord> | |
[_] <service=ident> | |
[.][_] <proto=(tcp | udp )> | |
[.] <name=hostname> | |
<ttl=num> IN SRV | |
<priority=num> | |
<weight=num> | |
<port=num> | |
<target=hostname> | |
\n | |
<rule:txtrecord> | |
<entry=hostname> | |
<ttl=num> IN TXT | |
\" <txt=(?:[^\n]+)> \" \s* \n | |
<rule:soarecord> | |
<entry=hostname> | |
<ttl=num> IN SOA | |
<contact=hostname> | |
<serial=num> | |
<refresh=num> | |
<retry=num> | |
<expiry=num> | |
<rrttl=num> | |
\n | |
<rule:simplerecord> | |
<entry=hostname> | |
<ttl=num> IN <simplerecordtype> | |
<value=hostname> | |
\n | |
<rule:mxrecord> | |
<entry=hostname> | |
<ttl=num> IN <simplerecordtype> | |
<value=hostname> | |
<priority=num> | |
\n | |
<rule:simplerecordtype> ( NS | CNAME | A | AAAA ) | |
<rule:hostname> <.ident>(.<.ident>)*.? | |
<token:num> \d+ | |
<token:ident> ( [-a-z0-9]+ | \* ) | |
}xsm | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment