Skip to content

Latest commit

 

History

History
120 lines (89 loc) · 3.33 KB

README.md

File metadata and controls

120 lines (89 loc) · 3.33 KB

dns2

NPM version Build Status

A DNS Server and Client Implementation in Pure JavaScript with no dependencies.

Features

  • Server and Client
  • Lot of Type Supported
  • Extremely lightweight
  • DNS over UDP, TCP, HTTPS Supported

Installation

$ npm install dns2

Example Client

Lookup any records available for the domain lsong.org.

const DNS = require('dns2');

const dns = new DNS();

(async () => {
  const result = await dns.resolveA('google.com');
  console.log(result.answers);
})();

Example Server

const dns = require('..');

const { Packet } = dns;

const server = dns.createServer((request, send, rinfo) => {
  const response = Packet.createResponseFromRequest(request);
  const [ question ] = request.questions;
  const { name } = question;
  response.answers.push({
    name,
    type: Packet.TYPE.A,
    class: Packet.CLASS.IN,
    ttl: 300,
    address: '8.8.8.8'
  });
  send(response);
});

server.on('request', (request, response, rinfo) => {
  console.log(request.header.id, request.questions[0]);
});

server.listen(5333);

Then you can test your DNS server:

$ dig @127.0.0.1 -p5333 lsong.org

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

API

  • dns2.createServer()
  • dns2.lookup()
  • dns2.Packet()
  • dns2.Client()
  • dns2.Server()

Relevant Specifications

Contributing

  • Fork this Repo first
  • Clone your Repo
  • Install dependencies by $ npm install
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Publish your local branch, Open a pull request
  • Enjoy hacking <3

MIT license

Copyright (c) 2016 lsong

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.