Name: zonefile-pegjs
Owner: TABLEFLIP
Description: A PEG.js grammar for parsing zonefile DNS configuration
Created: 2015-12-26 11:04:14.0
Updated: 2016-10-03 00:23:49.0
Pushed: 2015-12-29 02:08:18.0
Homepage: null
Size: 42
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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 zonefile-pegjs
Use pegjs to build the parser, or use pegjs-require to require
the grammar file directly:
ire('pegjs-require')
parser = require('zonefile-pegjs')
er.parse('tableflip.io. 21599 IN A 178.62.82.182')
origin: null, ttl: null, records:[ { name:'tableflip.io.', ttl: '21599', type:'A', data: '178.62.82.182' } ] }
fs = require('fs')
test = require('tape')
pegjs = require('pegjs-require')
('Parse zonefile for example.org.', function (t) {
r zone = fs.readFileSync(__dirname + '/example.zone', 'utf8')
r parser = require('../zonefile.pegjs')
r actual = parser.parse(zone)
r expected = require('./example.json')
deepEquals(actual, expected, 'Most excellent: Parser generates expected output for example.org.')
end()
So given a zonefile like: example.zone
ne file for example.org
2d ; 172800 secs default TTL for zone
GIN 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.
IN A 192.168.254.3
IN CNAME joe
The parser will produce: example.json
rigin": "example.org.",
tl": "2d",
ecords": [
{
"name": "@",
"ttl": null,
"type": "SOA",
"data": {
"nameServer": "ns1.example.org.",
"email": "hostmaster.example.org.",
"serial": "2003080800",
"refresh": "12h",
"retry": "15m",
"expiry": "3w",
"minimum": "3h"
}
},
{
"name": " ",
"ttl": null,
"type": "NS",
"data": "ns1.example.org."
},
{
"name": " ",
"ttl": null,
"type": "MX",
"data": {
"preference": "10",
"domain": "mail.example.org."
}
},
{
"name": "joe",
"ttl": null,
"type": "A",
"data": "192.168.254.3"
},
{
"name": "www",
"ttl": null,
"type": "CNAME",
"data": "joe"
}
A (?°?°???TABLEFLIP side project.