Skip to content

Latest commit

 

History

History
68 lines (41 loc) · 1.26 KB

README.md

File metadata and controls

68 lines (41 loc) · 1.26 KB

minimal-dns

A minimal, zero dependencies DNS parser and server write by Node.js. Best for learning structure of DNS message.

Dependencies

Node.js

Usage

Example

There is a basic example in main.js

simply run

node main

under the project directory you can start a dns server on your ip (redirecting the google DNS).

DNS Parser

Using

const DNSMessage = require('./dns-parser');

you can import the DNSMessage class, it has toBuffer() and fromBuffer() methods that can parse DNS message from Buffer, or encode DNS Message to Buffer.

DNSServer

Using

const { DNSServer, DNSRecord } = require('./dns-server');

you can import the DNSServer class。

With

var dnsServer = new DNSServer();

you can start a DNS Server on 0.0.0.0:53 (Port 53 of all available IPs on your computer).

The DNSServer class has a addRecord method, With

dnsServer.addRecord(new DNSRecord("example.com.", "1.1.1.1"));

you can add a custom DNS Records to your DNS Server.

Functions

DNS Parser

  • Parse DNS Message From Socket Message
  • Encode DNS Message to Socket Message

DNS Server

  • Can add some Custom DNS Records
  • Can setup a remote DNS Server and redirect the query (When missing custom DNS Records)