zonefile-pegjs
A PEG.js grammar for parsing zonefile DNS configuration to JSON. Handles multi-line SOA and TXT records, as well as SRV, MX, CNAME, NS, AAAA, A and friends.
See zonefile.pegjs for the magic. You can try it out by pasting it into the PEG.js web dingus: http://pegjs.org/online
Derived from, and with thanks to, Pro DNS and BIND by Ron Aitchison. See: http://www.zytrax.com/books/dns/ch8/
Install
npm install zonefile-pegjs
Usage
Use pegjs to build the parser, or use pegjs-require to require
the grammar file directly:
var parser = parser// { origin: null, ttl: null, records:[ { name:'tableflip.io.', ttl: '21599', type:'A', data: '178.62.82.182' } ] }
Example
var fs = var test = var pegjs =
So given a zonefile like: example.zone
; zone file for example.org$TTL 2d ; 172800 secs default TTL for zone$ORIGIN example.org.@ IN SOA ns1.example.org. hostmaster.example.org. ( 2003080800 ; se = serial number 12h ; ref = refresh 15m ; ret = update retry 3w ; ex = expiry 3h ; min = minimum ) IN NS ns1.example.org. IN MX 10 mail.example.org.joe IN A 192.168.254.3www IN CNAME joe
The parser will produce: example.json
A (╯°□°)╯︵TABLEFLIP side project.