1.0.1 • Published 3 years ago

node-ddns v1.0.1

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

node-ddns

NPM version stability-stable version maintained maintainer License

A DNS Client, Server and DDNS Implementation in Pure JavaScript, only dependant on dns-packet and node-ip. Huge thanks to dns2 for inspiration and lots of smart code.

Features

  • UDPClient, TCPClient, TLSClient, DOHClient
  • UDPServer, TCPServer, TLSServer, DOHServer
  • Support a massive amount of record types
  • Supports DNSSEC
  • Extremely lightweight and simple to use
  • Many detailed samples to get you started
  • Supports Dyndns2 update via http if running DOHServer!
  • Basic json-zone-file handing built in

Installation

npm install node-ddns

Example Client

Most simple lookup the A-record for the domain google.com.

const ddns = require('node-ddns');
const dns = new ddns();

dns.ResolveA('www.google.com').then((result)=>{
    console.log(result.answers);
}).catch((error)=>{
    console.log(error);
});

Example Server

const ddns = require('../..');
const server = new ddns.UDPServer({port:53});

server.listen().then(()=>{
    console.log(`Listening on ${server.address}:${server.port}`);
})

server.on('request', (request, response, rinfo) => {
    request.questions.forEach(function (question) {
        var answers = [{
            "name":question.name,
            "type":"A",
            "ttl":300,
            "data":"192.168.100.55"}];
        response(ddns.ServerUtilities.createSuccessResponseFromRequest(request,answers));
    });
});

Then you can test your DNS server:

$ dig @127.0.0.1 test.com
c:\> nslookup test.com 127.0.0.1

Note that when implementing your own lookups, the contents of the query will be found in request.questions[0].name.

Examples

npm run example-client-simple
npm run example-client-udp
npm run example-client-tcp
npm run example-client-tls
npm run example-client-doh
npm run example-server-udp
npm run example-server-tcp
npm run example-server-tls
npm run example-server-doh
npm run example-server-ddns
npm run example-server-recursive