• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A DNS zone file generator and parser written in Javascript.

dns-zonefile

An RFC1035 compliant DNS zone file parser and generator for Node.js and browser.

Installation

Deno

import zonefile from 'https://deno.land/x/[email protected]/lib/zonefile.js';

Standalone

npm install dns-zonefile -g

Module

npm install dns-zonefile

Usage

Zone Information

dns-zonefile accepts both zone data expressed as a JSON object or plain text zone file. It supports SOA, NS, A, AAAA, CNAME, MX, PTR, SRV, SPF, CAA, DS and TXT record types as well as the $ORIGIN keyword (for zone-wide use only). Each record type (and the $ORIGIN keyword) is optional, though bind expects to find at least an SOA record in a valid zone file.

Examples

Forward DNS Zone

The following JSON produces a zone file for a forward DNS zone:

{
    "$origin": "MYDOMAIN.COM.",
    "$ttl": 3600,
    "soa": {
        "mname": "NS1.NAMESERVER.NET.",
        "rname": "HOSTMASTER.MYDOMAIN.COM.",
        "serial": "{time}",
        "refresh": 3600,
        "retry": 600,
        "expire": 604800,
        "minimum": 86400
    },
    "ns": [
        { "host": "NS1.NAMESERVER.NET." },
        { "host": "NS2.NAMESERVER.NET." }
    ],
    "a": [
        { "name": "@", "ip": "127.0.0.1" },
        { "name": "www", "ip": "127.0.0.1" },
        { "name": "mail", "ip": "127.0.0.1" }
    ],
    "aaaa": [
        { "ip": "::1" },
        { "name": "mail", "ip": "2001:db8::1" }
    ],
    "cname":[
        { "name": "mail1", "alias": "mail" },
        { "name": "mail2", "alias": "mail" }
    ],
    "mx":[
        { "preference": 0, "host": "mail1" },
        { "preference": 10, "host": "mail2" }
    ],
    "txt":[
        { "name": "txt1", "txt": "hello" },
        { "name": "txt2", "txt": "world" }
    ],
    "srv":[
        { "name": "_xmpp-client._tcp", "target": "jabber", "priority": 10, "weight": 0, "port": 5222 },
        { "name": "_xmpp-server._tcp", "target": "jabber", "priority": 10, "weight": 0, "port": 5269 }
    ]
}

dns-zonefile will produce the following zone file from the above information, while the following zone file can as well be parsed to produce the zone file like above:

; Zone: MYDOMAIN.COM.
; Exported  (yyyy-mm-ddThh:mm:ss.sssZ): 2014-09-22T21:10:36.697Z

$ORIGIN MYDOMAIN.COM.
$TTL 3600

; SOA Record
@	 		IN	SOA	NS1.NAMESERVER.NET.	HOSTMASTER.MYDOMAIN.COM.	(
			1411420237	 ;serial
			3600	 ;refresh
			600	 ;retry
			604800	 ;expire
			86400	 ;minimum ttl
)

; NS Records
@	IN	NS	NS1.NAMESERVER.NET.
@	IN	NS	NS2.NAMESERVER.NET.

; MX Records
@	IN	MX	0	mail1
@	IN	MX	10	mail2

; A Records
@	IN	A	127.0.0.1
www	IN	A	127.0.0.1
mail	IN	A	127.0.0.1

; AAAA Records
@	IN	AAAA	::1
mail	IN	AAAA	2001:db8::1

; CNAME Records
mail1	IN	CNAME	mail
mail2	IN	CNAME	mail

; TXT Records
txt1	IN	TXT	"hello"
txt2	IN	TXT	"world"

; SRV Records
_xmpp-client._tcp	IN	SRV	10	0	5222	jabber
_xmpp-server._tcp	IN	SRV	10	0	5269	jabber

Reverse DNS Zone

This JSON will produce a zone file for a reverse DNS zone (the $ORIGIN keyword is recommended for reverse DNS zones):

{
	"$origin": "0.168.192.IN-ADDR.ARPA.",
	"$ttl": 3600,
	"soa": {
		"mname": "NS1.NAMESERVER.NET.",
		"rname": "HOSTMASTER.MYDOMAIN.COM.",
		"serial": "{time}",
		"refresh": 3600,
		"retry": 600,
		"expire": 604800,
		"minimum": 86400
	},
  "ns": [
      { "host": "NS1.NAMESERVER.NET." },
      { "host": "NS2.NAMESERVER.NET." }
  ],
  "ptr":[
      { "name": 1, "host": "HOST1.MYDOMAIN.COM." },
      { "name": 2, "host": "HOST2.MYDOMAIN.COM." }
  ]
}

dns-zonefile will produce the following zone file from the above information, while the following zone file can as well be parsed to produce the zone file like above:

; Zone: 0.168.192.IN-ADDR.ARPA.
; Exported  (yyyy-mm-ddThh:mm:ss.sssZ): 2014-09-22T21:10:36.698Z

$ORIGIN 0.168.192.IN-ADDR.ARPA.
$TTL 3600

; SOA Record
@	 		IN	SOA	NS1.NAMESERVER.NET.	HOSTMASTER.MYDOMAIN.COM.	(
			1411420237	 ;serial
			3600	 ;refresh
			600	 ;retry
			604800	 ;expire
			86400	 ;minimum ttl
)

; NS Records
@	IN	NS	NS1.NAMESERVER.NET.
@	IN	NS	NS2.NAMESERVER.NET.

; PTR Records
1	IN	PTR	HOST1.MYDOMAIN.COM.
2	IN	PTR	HOST2.MYDOMAIN.COM.

Standalone Usage

To use dns-zonefile to generate a zone file from JSON from the command line, place the desired JSON data in a file (zonefile_data.json in this example) and run the following command. Note that the resulting zone file will be printed to the console; to save the zone file to disk (my_zone.conf in this example), use redirection as in this example:

zonefile -g zonefile_data.json > my_zone.conf

To use dns-zonefile to parse a zone file to JSON from the command line, place the desired zone file data in a file (zonefile_data.txt in this example) and run the following command. Note that the resulting JSON will be printed to the console; to save the JSON to disk (my_zone.json in this example), use redirection as in this example:

zonefile -p zonefile_data.txt > my_zone.json

If the -g and -p are omitted, -g will be assumed if the lower cased filename contains .json, otherwise, -p will be assumed.

zonefile -v or zonefile --version will print the version information.

Module Usage

dns-zonefile can also be used as a module. Simply use require() to include it, then invoke its generate() function as shown in the following example:

import fs from 'fs';
import zonefile from 'dns-zonefile';
const json = fs.readFileSync('./zonefile_forward.json', 'utf8');
const options = JSON.parse(json);
const output = zonefile.generate(options);
console.log(output);

options can either be a parsed JSON object as shown above, or a regular Javascript object containing the same required fields.

It is also possible to parse a zone file to JSON by invoking its parse() function as shown in the following example:

import fs from 'fs';
import zonefile from 'dns-zonefile';
var text = fs.readFileSync('./zonefile_forward.txt', 'utf8');
output = zonefile.parse(text);
console.log(JSON.stringify(output));

License

ISC License (ISC)

Copyright (c) 2014, Qian Chen

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

More Repositories

1

jsonql

JSON query expression library in Golang.
Go
275
star
2

gojq

JSON query in Golang
Go
190
star
3

gosqljson

A Go library to work with SQL database
Go
63
star
4

filesync

Filesync is a utility written in Golang which helps you to keep the files on the client up to date with the files on the server.
Go
60
star
5

leanweb

Builds framework agnostic web components.
JavaScript
48
star
6

gosqlapi

Turns any SQL database into a RESTful API.
Go
45
star
7

ip6

IPv6 address helper utilities.
JavaScript
20
star
8

splitargs

Splits strings into tokens by given separator, treating quoted part as a single token.
JavaScript
17
star
9

gostrgen

Random string generator in Golang.
Go
16
star
10

gosqlcrud

A Go library to work with SQL database using standard `database/sql` api. It supports SQL to array/maps/structs, and CRUD operations on structs.
Go
12
star
11

nproxy

A nodejs proxy server.
JavaScript
10
star
12

parse5

Ported from inikulin/parse5 but for Deno.
JavaScript
9
star
13

FSK

This is an iOS based signal generator.
Objective-C
7
star
14

azui

A set of more desktop/mobile/touchscreen friendly web UI components.
JavaScript
7
star
15

gproxy

Go Proxy
Go
7
star
16

vpn-route

Sometime you just need it. F*** GFW.
6
star
17

curl-parser

curl command parser.
JavaScript
6
star
18

MyNotes

A collection of my frequently used scripts.
C++
4
star
19

mf_proxmox_kvm_scripts

Scripts for kvm templates for Modules Factory Proxmox WHMCS modules.
Shell
4
star
20

goweb

Multi domain/host web server written in Golang.
Go
4
star
21

gorest

A restful framework in Golang.
Go
3
star
22

yotta-node

Yotta DB is a local file based key value database, written in Node.js.
JavaScript
3
star
23

optional

If you think if err != nil is too much, this might be for you.
Go
3
star
24

metal_gpu

Working with Metal GPU in C++ and Swift
C++
2
star
25

gosplitargs

Splits strings into tokens by given separator except treating quoted part as a single token.
Go
2
star
26

url_shortener

Yet another url shortener.
JavaScript
2
star
27

mnist-view

View mnist images in command line, in Deno
TypeScript
2
star
28

images

CNN Proof of Concept.
JavaScript
2
star
29

wsl

Web SQL Lite (Golang)
Go
2
star
30

ip6.sh

ip6.sh website.
JavaScript
2
star
31

dnd

drag and drop
JavaScript
1
star
32

cpp_code

CPP code.
C++
1
star
33

leanweb-pub-sub-demo

This project demonstrates how Leanweb helps web components to talk to each other.
JavaScript
1
star
34

gr

A go restful service, extensible by interceptors.
Go
1
star
35

jwt

JWT encoder/decoder/verifier.
Go
1
star
36

sso-client

SSO client app powered by Leanweb.
JavaScript
1
star
37

exparser

An expression parser.
Go
1
star
38

go

Go game with reinforcement learning.
C++
1
star
39

server_monitor

Server monitor project based on Net Data.
Shell
1
star
40

jsstrgen

Random string generator in Javascript.
JavaScript
1
star
41

sso

SSO login app powered by Leanweb.
JavaScript
1
star
42

gorediscache

Go redis cache.
Go
1
star
43

ann

Artificial Neural Network Proof of Concept
TypeScript
1
star
44

websql

Run SQL over the web - Backend made easier.
Go
1
star
45

maze

An experimental project for reinforcement learning.
C++
1
star
46

dataslots

http/websocket data slots.
Go
1
star
47

secretrest

secretrest
C
1
star
48

ui

A css only ui library.
JavaScript
1
star
49

nn

World simplest neural network.
C++
1
star
50

website-seed

Web site seed.
CSS
1
star
51

netdata

Backend of netdata.io.
Go
1
star
52

sgf2go-cpp

SGF Go game parser and generator.
C++
1
star
53

gammu-gateway

A gammu SMS service gateway.
Go
1
star
54

large-comments

A VS Code plugin that generate large comments.
TypeScript
1
star
55

leanweb.app

leanweb.app website source code.
JavaScript
1
star
56

wsld

wsl daemon
Go
1
star
57

archlinux_scripts

Arch Linux Scripts
Shell
1
star
58

netdata2

An SQL backend for the web.
Go
1
star
59

signal

A command and broadcast based multi channel message hub.
Go
1
star
60

sgf2go

SGF Go game parser and generator.
JavaScript
1
star
61

gorest2

This is to continue gorest with incompatible changes.
Go
1
star
62

byoc

Bring your own cloud.
Go
1
star
63

ppw

Pixel Perfect Works.
JavaScript
1
star