A minimal, zero dependencies DNS parser and server write by Node.js. Best for learning structure of DNS message.
Node.js
There is a basic example in main.js
simply run
node mainunder the project directory you can start a dns server on your ip (redirecting the google DNS).
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.
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.
- Parse DNS Message From Socket Message
- Encode DNS Message to Socket Message
- Can add some Custom DNS Records
- Can setup a remote DNS Server and redirect the query (When missing custom DNS Records)