npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

massdns

v1.1.2

Published

MassDNS wrapper for node.js

Downloads

7

Readme

node-massdns

Version npm Npm package total downloads Visitors node.js version Module type: CJS js-semistandard-style jsDocs.io Unit test status npm bundle size npm bundle size License

MassDNS wrapper for node.js

What is MassDNS

Quoted from MassDNS github:

MassDNS is a simple high-performance DNS stub resolver targeting those who seek to resolve a massive amount of domain names in the order of millions or even billions. Without special configuration, MassDNS is capable of resolving over 350,000 names per second using publicly available resolvers.

Requirements

  • node.js >= v16.x
  • massdns binary Tested using up-to-date master branch and latest release (massdns v1.0.0)
  • File containing list of resolvers to use. You can use file generated by get-resolvers.py script from MassDNS.

Installation

npm i massdns

Usage

const { massdns, lookup } = require('massdns');

(async () => {
  const massdnsResults = await massdns(
    [
      'example.org',
      'www.github.com'
    ],
    {
      resolvers: [
        '8.8.8.8',
        '8.8.4.4',
        '1.1.1.1'
      ]
    }
  );

  lookup('example.org', massdnsResults);
  lookup('www.github.com', massdnsResults);
})();

Result example

massdns

[
  {
    "name": "example.org.",
    "type": "A",
    "class": "IN",
    "status": "NOERROR",
    "rx_ts": 1703233801103924700,
    "data": {
      "answers": [
        {
          "ttl": 1633,
          "type": "A",
          "class": "IN",
          "name": "example.org.",
          "data": "93.184.216.34"
        }
      ]
    },
    "flags": [
      "rd",
      "ra"
    ],
    "resolver": "8.8.4.4:53",
    "proto": "UDP"
  },
  {
    "name": "www.example.org.",
    "type": "A",
    "class": "IN",
    "status": "NOERROR",
    "rx_ts": 1703233801108079900,
    "data": {
      "answers": [
        {
          "ttl": 15373,
          "type": "A",
          "class": "IN",
          "name": "www.example.org.",
          "data": "93.184.216.34"
        }
      ]
    },
    "flags": [
      "rd",
      "ra"
    ],
    "resolver": "8.8.4.4:53",
    "proto": "UDP"
  },
  {
    "name": "www.github.com.",
    "type": "A",
    "class": "IN",
    "status": "NOERROR",
    "rx_ts": 1703233801111802600,
    "data": {
      "answers": [
        {
          "ttl": 3487,
          "type": "CNAME",
          "class": "IN",
          "name": "www.github.com.",
          "data": "github.com."
        },
        {
          "ttl": 60,
          "type": "A",
          "class": "IN",
          "name": "github.com.",
          "data": "140.82.112.3"
        }
      ]
    },
    "flags": [
      "rd",
      "ra"
    ],
    "resolver": "8.8.4.4:53",
    "proto": "UDP"
  },
  {
    "name": "asd.am21l32ml2.com.",
    "type": "A",
    "class": "IN",
    "status": "NXDOMAIN",
    "rx_ts": 1703233801120768500,
    "data": {
      "authorities": [
        {
          "ttl": 900,
          "type": "SOA",
          "class": "IN",
          "name": "com.",
          "data": "a.gtld-servers.net. nstld.verisign-grs.com. 1703233784 1800 900 604800 86400"
        }
      ]
    },
    "flags": [
      "rd",
      "ra"
    ],
    "resolver": "8.8.4.4:53",
    "proto": "UDP"
  }
]

lookup('www.gihub.com', massdnsResults)

[
  {
    "ttl": 3487,
    "type": "CNAME",
    "class": "IN",
    "name": "www.github.com.",
    "data": "github.com."
  },
  {
    "ttl": 60,
    "type": "A",
    "class": "IN",
    "name": "github.com.",
    "data": "140.82.112.3"
  }
]

returnAsKeyValueObject option

Looking up item on big array is inefficient. For processing big result, consider to use "returnAsKeyValueObject" option. Return value will be a key-value object so you can lookup easily without "lookup" method in more efficient.

const { massdns, lookup } = require('massdns');

(async () => {
  const massdnsResults = await massdns(
    [
      'example.org',
      'www.github.com'
    ],
    {
      resolvers: [
        '8.8.8.8',
        '8.8.4.4',
        '1.1.1.1'
      ],
      returnAsKeyValueObject: true
    }
  );
})();

Will return:

{
  "example.org.": {
    "name": "example.org.",
    "type": "A",
    "class": "IN",
    "status": "NOERROR",
    "rx_ts": 1703233801103924700,
    "data": {
      "answers": [
        {
          "ttl": 1633,
          "type": "A",
          "class": "IN",
          "name": "example.org.",
          "data": "93.184.216.34"
        }
      ]
    },
    "flags": [
      "rd",
      "ra"
    ],
    "resolver": "8.8.4.4:53",
    "proto": "UDP"
  },
  "www.github.com": {
    "name": "www.github.com.",
    "type": "A",
    "class": "IN",
    "status": "NOERROR",
    "rx_ts": 1703233801111802600,
    "data": {
      "answers": [
        {
          "ttl": 3487,
          "type": "CNAME",
          "class": "IN",
          "name": "www.github.com.",
          "data": "github.com."
        },
        {
          "ttl": 60,
          "type": "A",
          "class": "IN",
          "name": "github.com.",
          "data": "140.82.112.3"
        }
      ]
    },
    "flags": [
      "rd",
      "ra"
    ],
    "resolver": "8.8.4.4:53",
    "proto": "UDP"
  }
}

API

massdns(hostnames, [options])

/**
 * Call massdns
 *
 * @param {string[]} hostnames
 * @param {MassDNSOptions} [options] - at lease specify resolvers or resolverFile
 * @returns {Promise<MassDnsResultItem[]|object>}
 */
async (hostnames, options);

hostnames: array of hostname string

options: optional object

/**
 * @typedef MassDNSOptions
 * @type {object}
 *
 * @property {string} [bin] - massdns binary file to use, will use "massdns" from $PATH if not specified
 * @property {string[]} [resolvers] - resolvers to use, ignored if resolverFile option specifed
 * @property {string} [resolverFile] - file containing resolvers, will override resolvers option
 * @property {string} [tempDir] - temp dir, will use temp dir from OS if not specified
 * @property {boolean} [preserveTempDir] - do not delete temp dir at end, default to true if tempDir specified and false if tempDir not specified
 * @property {string} [logFile] - massdns log file
 * @property {number} [hashMapSize] - optional number of concurent lookup, will use massdns default if not specified (10000)
 * @property {boolean} [returnAsKeyValueObject] - if it is set to true, will return key-value object instead of array of MassDnsResultItem
 */

Known issues

MassDNS is very fast and has very little memory footprint. But using this wrapper might produce high memory usage (around 400-500 MB for 100k hostnames) because this wrapper wraps the result in ready to use json so you can traverse it just like a standard array of object in javascript. Passing big object on javascript would also have big impact, but I think it's still acceptable on my use.

I have consider to pass result as file (not passing result as array of object values), but I think it just defeat our goal to provide easy to access MassDNS result.

Let me know if you have any consideration or recomendation. Please raise an issue. I will very happy if there is someone has interest and care of this package.

If you want to lookup on big result, use returnAsKeyValueObject option. It will improve lookup speed dramatically.

Changelog

See CHANGELOG.md file.

See also