vigour-io/api-promise · index.js
javascript logo
function lookup (host, options, cb) {
  if (!cb) {
    cb = options
    options = null
  }
  if (dnsCache[host] && dnsCache[host][2] > +new Date() - 6e4) {
    clearTimeout(dnsCache[host][3])
    dnsCache[host][3] = setTimeout(() => { delete dnsCache[host] }, 500)
    cb(null, dnsCache[host][0], dnsCache[host][1])
  } else {
    if (dnsCache[host]) {
      clearTimeout(dnsCache[host][3])
      delete dnsCache[host]
    }
    dns.lookup(host, options, (err, ip, type) => {
      if (err) {
        cb(err)
      } else {
        dnsCache[host] = [ip, type, +new Date()]
        dnsCache[host][3] = setTimeout(() => { delete dnsCache[host] }, 500)
        cb(null, dnsCache[host][0], dnsCache[host][1])
      }
    })
  }
}
Similar code snippets
1.
avwo/whistle · dns.js
Match rating: 59.76% · See similar code snippets
javascript logo
function lookup(hostname, callback, allowDnsCache) {
  var host = allowDnsCache ? dnsCache[hostname] : null;
  var cacheTime;
  if (host) {
    cacheTime = Date.now() - host.time;
  }
  if (host && cacheTime < MAX_CACHE_TIME) {
    callback(null, host.ip);
    if (cacheTime > CACHE_TIME) {
      lookupDNS(host.hostname);
    }
    return host.ip;
  }
  lookupDNS(hostname, function(err, ip) {
    err ? lookupDNS(hostname, callback) : callback(err, ip);
  });
}
2.
avwo/whistle · dns.js
Match rating: 59.42% · See similar code snippets
javascript logo
function execCallback(err, ip) {
    if (!err) {
      dnsCache[hostname] = {
        ip: ip,
        hostname: hostname,
        time: Date.now()
      };
    }
    if (done) {
      return;
    }
    done = true;
    var host = dnsCache[hostname];
    callbacks[hostname] = null;
    list.forEach(function(callback) {
      callback(err, host && host.ip);
    });
  }
3.
tvrprasad/sspi-client · fqdn.js
Match rating: 56.62% · See similar code snippets
javascript logo
function getFqdnForIpAddress(ipAddress, cb) {
  dns.reverse(ipAddress, function(err, fqdns) {
    if (err) {
      cb(err, fqdns);
    } else if (fqdns[0].toLowerCase() === localhostIdentifier) {
      getFqdn(localhostIdentifier, cb);
    } else {
      cb(err, fqdns[0]);
    }
  });
}
4.
tvrprasad/sspi-client · fqdn.js
Match rating: 54.52% · See similar code snippets
javascript logo
function(err, fqdns) {
    if (err) {
      cb(err, fqdns);
    } else if (fqdns[0].toLowerCase() === localhostIdentifier) {
      getFqdn(localhostIdentifier, cb);
    } else {
      cb(err, fqdns[0]);
    }
  }
5.
obliquid/jslardo · jquery.jstree.js
Match rating: 53.36% · See similar code snippets
javascript logo
function () {
						if(this.data.dnd.to1) { clearTimeout(this.data.dnd.to1); }
						if(this.data.dnd.to2) { clearTimeout(this.data.dnd.to2); }
						if(this.data.dnd.i1) { clearInterval(this.data.dnd.i1); }
						if(this.data.dnd.i2) { clearInterval(this.data.dnd.i2); }
						this.data.dnd.after		= false;
						this.data.dnd.before	= false;
						this.data.dnd.inside	= false;
						this.data.dnd.off		= false;
						this.data.dnd.prepared	= false;
						this.data.dnd.w			= false;
						this.data.dnd.to1		= false;
						this.data.dnd.to2		= false;
						this.data.dnd.i1		= false;
						this.data.dnd.i2		= false;
						this.data.dnd.active	= false;
						this.data.dnd.foreign	= false;
						if(m) { m.css({ "top" : "-2000px" }); }
						if(ml) { ml.css({ "top" : "-2000px" }); }
					}
6.
avwo/whistle · dns.js
Match rating: 52.31% · See similar code snippets
javascript logo
function lookupDNS(hostname, callback) {
  var list = callbacks[hostname];
  if (list) {
    if (callback) {
      list.push(callback);
    }
    return;
  }
  callbacks[hostname] = list = [];
  if (callback) {
    list.push(callback);
  }
  var done;
  function execCallback(err, ip) {
    if (!err) {
      dnsCache[hostname] = {
        ip: ip,
        hostname: hostname,
        time: Date.now()
      };
    }
    if (done) {
      return;
    }
    done = true;
    var host = dnsCache[hostname];
    callbacks[hostname] = null;
    list.forEach(function(callback) {
      callback(err, host && host.ip);
    });
  }

  var timer = setTimeout(function() {
    execCallback(new Error('Timeout'));
  }, TIMEOUT);

  try {
    dns.lookup(hostname, function (err, ip, type) {
      clearTimeout(timer);
      if (err) {
        execCallback(err);
      } else {
        execCallback(null, ip || getDefaultIp(type));
      }
    });
  } catch(err) {//如果断网,可能直接抛异常,https代理没有用到error-handler
    execCallback(err);
  }
}
7.
avwo/whistle · tunnel.js
Match rating: 51.04% · See similar code snippets
javascript logo
function getServerIp(url, callback, hostIp, hostPort) {
          var hostHandler = function(err, ip, port, host) {
            if (host) {
              _rules.host = host;
            }
            data.requestTime = data.dnsTime = Date.now();
            req.hostIp = resData.ip = ip || LOCALHOST;
            reqEmitter.emit('send', data);
            err ? emitError(err) : callback(ip, port);
          };
          if (hostIp) {
            hostHandler(null, hostIp, hostPort);
          } else {
            req.curUrl = url;
            rules.resolveHost(req, hostHandler, rulesMgr, req.rulesFileMgr, req.headerRulesMgr);
          }
        }
8.
imweb/node-pac · dnsResolve.js
Match rating: 50.73% · See similar code snippets
javascript logo
function (dnsResolve) {
  if (typeof dnsResolve !== 'function') {
    dnsResolve = null;
  }
  return function (host) {
    if (dnsResolve && !net.isIP(host)) {
      host = dnsResolve(host);
    }
    return net.isIP(host) ? host : '0.0.0.0';
  };
}
9.
avwo/whistle · index.js
Match rating: 50.54% · See similar code snippets
javascript logo
function getServerIp(url, callback, hostIp, hostPort) {
      if (plugin) {
        return callback(LOCALHOST);
      }
      var hostHandler = function(err, ip, port, host) {
        if (err) {
          return execCallback(err);
        }

        if (host) {
          _rules.host = host;
        }
        socket.hostIp = resData.ip = util.getHostIp(ip, port);
        data.requestTime = data.dnsTime = Date.now();
        reqEmitter.emit('send', data);
        callback(ip, port);
      };
      if (hostIp) {
        hostHandler(null, hostIp, hostPort);
      } else {
        socket.curUrl = url;
        rules.resolveHost(socket, hostHandler, pluginRules, socket.rulesFileMgr, socket.headerRulesMgr);
      }
    }
10.
datastax/nodejs-driver · address-resolution.js
Match rating: 50.29% · See similar code snippets
javascript logo
function resolve(next) {
      dns.reverse(address, function (err, hostNames) {
        if (err) {
          return next(err);
        }
        if (!hostNames) {
          return next();
        }
        name = hostNames[0];
        next();
      });
    }