How to use dns - 10 common examples

To help you get started, we’ve selected a few dns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apigee / trireme / node12 / node12src / src / main / javascript / io / apigee / trireme / node12 / node / net.js View on Github external
dnsopts.hints = dns.ADDRCONFIG;
      // The AI_V4MAPPED hint is not supported on FreeBSD, and getaddrinfo
      // returns EAI_BADFLAGS. However, it seems to be supported on most other
      // systems. See
      // http://lists.freebsd.org/pipermail/freebsd-bugs/2008-February/028260.html
      // and
      // https://svnweb.freebsd.org/base/head/lib/libc/net/getaddrinfo.c?r1=172052&r2=175955
      // for more information on the lack of support for FreeBSD.
      if (process.platform !== 'freebsd')
        dnsopts.hints |= dns.V4MAPPED;
    }

    debug('connect: find host ' + host);
    debug('connect: dns options ' + dnsopts);
    self._host = host;
    dns.lookup(host, dnsopts, function(err, ip, addressType) {
      self.emit('lookup', err, ip, addressType);

      // It's possible we were destroyed while looking this up.
      // XXX it would be great if we could cancel the promise returned by
      // the look up.
      if (!self._connecting) return;

      if (err) {
        // net.createConnection() creates a net.Socket object and
        // immediately calls net.Socket.connect() on it (that's us).
        // There are no event listeners registered yet so defer the
        // error event to the next tick.
        process.nextTick(function() {
          self.emit('error', err);
          self._destroy();
        });
github nodekit-io / nodekit-darwin / src / nodekit / NKCore / lib-core / node / net.js View on Github external
dnsopts.hints = dns.ADDRCONFIG;
      // The AI_V4MAPPED hint is not supported on FreeBSD, and getaddrinfo
      // returns EAI_BADFLAGS. However, it seems to be supported on most other
      // systems. See
      // http://lists.freebsd.org/pipermail/freebsd-bugs/2008-February/028260.html
      // and
      // https://svnweb.freebsd.org/base/head/lib/libc/net/getaddrinfo.c?r1=172052&r2=175955
      // for more information on the lack of support for FreeBSD.
      if (process.platform !== 'freebsd')
        dnsopts.hints |= dns.V4MAPPED;
    }

    debug('connect: find host ' + host);
    debug('connect: dns options ' + dnsopts);
    self._host = host;
    dns.lookup(host, dnsopts, function(err, ip, addressType) {
      self.emit('lookup', err, ip, addressType);

      // It's possible we were destroyed while looking this up.
      // XXX it would be great if we could cancel the promise returned by
      // the look up.
      if (!self._connecting) return;

      if (err) {
        // net.createConnection() creates a net.Socket object and
        // immediately calls net.Socket.connect() on it (that's us).
        // There are no event listeners registered yet so defer the
        // error event to the next tick.
        process.nextTick(function() {
          self.emit('error', err);
          self._destroy();
        });
github neonious / lowjs / lib_js / net.js View on Github external
// been solved before in https://github.com/nodejs/node/pull/12342, but was
        // reverted as it had unintended side effects.
        if (Array.isArray(args[0]) && args[0][normalizedArgsSymbol])
            normalized = args[0];
        else
            normalized = normalizeArgs(args);
        let options = normalized[0];
        let cb = normalized[1];
        if (!options.host)
            options.host = '127.0.0.1';

        let family = options.port === undefined ? 0 : native.isIP(options.host);
        if (options.port === undefined || family)
            this._connect(options, family, options.port === undefined ? options.path : options.host, cb);
        else
            dns.lookup(options.host, (err, host, family) => {
                this.emit('lookup', err, options.host, family, host);
                if (err) {
                    this.connecting = false;
                    this._updateRef();

                    this.emit('error', err);
                    return;
                }
                if (this.destroyed) {
                    this.connecting = false;
                    this._updateRef();
                    return;
                }

                this._connect(options, family, host, cb);
            });
github per-gron / eminet / node / eminet.js View on Github external
var lookup = function(address, family, callback) {
    // implicit 'bind before send' needs to run on the same tick
    var matchedFamily = isIP(address);
    if (matchedFamily)
        return callback(null, address, matchedFamily);

    if (!dns)
        dns = require('dns');

    return dns.lookup(address, family, callback);
};
github datastax / nodejs-driver / lib / control-connection.js View on Github external
function resolve4(next) {
      dns.resolve4(name, function resolve4Callback(err, arr) {
        if (arr) {
          arr.forEach(address => addresses.push({ address, isIPv6: false }));
        }
        // Ignore error
        next();
      });
    },
    function resolve6(next) {
github apigee / trireme / node10 / node10tests / internet / test-dns.js View on Github external
TEST(function test_lookup_ipv4_explicit(done) {
  var req = dns.lookup('www.google.com', 4, function(err, ip, family) {
    if (err) throw err;
    assert.ok(net.isIPv4(ip));
    assert.strictEqual(family, 4);

    done();
  });

  checkWrap(req);
});
github graalvm / graaljs / test / disabled / test-dns.js View on Github external
return function(errr, stdout) {
    var expected = stdout.substr(0, stdout.length - 1).split('\n');

    var reversing = dns.reverse(myIp, function(error, domains, ttl, cname) {
      if (error) domains = [];
      cmpResults(expected, domains, ttl, cname);
    });
  }
}
github apigee / trireme / node10 / node10tests / internet / test-dns.js View on Github external
TEST(function test_lookup_localhost_ipv4(done) {
  var req = dns.lookup('localhost', 4, function(err, ip, family) {
    if (err) throw err;
    assert.strictEqual(ip, '127.0.0.1');
    assert.strictEqual(family, 4);

    done();
  });

  checkWrap(req);
});
github graalvm / graaljs / test / mjsunit / disabled / test-dns.js View on Github external
resolution.addCallback(function (addresses, ttl, cname) {
    puts("addresses: " + JSON.stringify(addresses));
    puts("ttl: " + JSON.stringify(ttl));
    puts("cname: " + JSON.stringify(cname));

    for (var i = 0; i < addresses.length; i++) {
      var a = addresses[i];
      var reversing = dns.reverse(a);
      reversing.addCallback( function (domains, ttl, cname) {
        puts("reverse for " + a + ": " + JSON.stringify(domains));
      });
      reversing.addErrback( function (code, msg) {
        puts("reverse for " + a + " failed: " + msg);
      });
    }
  });
github apigee / trireme / node10 / node10tests / internet / test-dns.js View on Github external
TEST(function test_resolve4(done) {
  var req = dns.resolve4('www.google.com', function(err, ips) {
    if (err) throw err;

    assert.ok(ips.length > 0);

    for (var i = 0; i < ips.length; i++) {
      assert.ok(isIPv4(ips[i]));
    }

    done();
  });

  checkWrap(req);
});

dns

A DNS Server with a REST API

MIT
Latest version published 10 years ago

Package Health Score

42 / 100
Full package analysis