MalwareHashRegistry.prototype.queryDns = function (digest, callback) {
  var that = this;

  var domainRoot = 'malware.hash.cymru.com';
  var domain = digest + '.' + domainRoot;
  dns.resolve(domain, 'TXT', function (err, addresses) {
    if (err) {
      if (err.code === dns.NOTFOUND) {
        callback(null);
        return;
      }

      throw err;
    }

    var response = addresses[0];
    var chunks = response.split(' ');
    var timestamp = that._parseAndConvertTimestamp(chunks[0]);
    var detectionRate = chunks[1];

    var result = {};
    result[digest] = {
      timestamp: timestamp,
      detectionRate: detectionRate
    };
    callback(result);
  });
};
Example #2
0
 prepareDns(DnsServer.testResolveCNAME(cname), function() {
   dns.resolve("vertx.io", 'CNAME', function(err, records) {
     vassert.assertNotNull(records);
     vassert.assertTrue("Unexpected address: " + records, cname === records[0]);
     vassert.testComplete();
   });
 });
Example #3
0
File: dnsbl.js Project: ddub/Haraka
 zones.forEach(function(zone) {
     self.logdebug("Querying: " + reverse_ip + "." + zone);
     dns.resolve(reverse_ip + "." + zone, "TXT", function (err, value) {
         if (!remaining_zones.length) return;
         remaining_zones.pop(); // we don't care about order really
         if (err) {
             switch (err.code) {
                 case dns.NOTFOUND:
                 case dns.NXDOMAIN:
                 case 'ENOTFOUND':
                                     break;
                 default:
                     self.loginfo("DNS error: " + err);
             }
             if (remaining_zones.length === 0) {
                 // only call declined if no more results are pending
                 return next();
             }
             return;
         }
         remaining_zones = [];
         return next(DENY, value);
     });
     
     remaining_zones.push(zone);
 });
Example #4
0
HMailItem.prototype.try_deliver = function () {
    var self = this;
    delivery_concurrency++;

    // check if there are any MXs left
    if (this.mxlist.length === 0) {
        return this.temp_fail("Tried all MXs");
    }
    
    var host = this.mxlist.shift().exchange;
    
    this.loginfo("Looking up A records for: " + host);

    // now we have a host, we have to lookup the addresses for that host
    // and try each one in order they appear
    dns.resolve(host, function (err, addresses) {
        if (err) {
            self.logerror("DNS lookup of " + host + " failed: " + err);
            delivery_concurrency--;
            return self.try_deliver(); // try next MX
        }
        if (addresses.length === 0) {
            // NODATA or empty host list
            self.logerror("DNS lookup of " + host + " resulted in no data");
            delivery_concurrency--;
            return self.try_deliver(); // try next MX
        }
        self.hostlist = addresses;
        self.try_deliver_host();
    });
}
Example #5
0
function resolve(protocol, serviceIdKey, serverUrlKey, configKey, resolveFn, errFn) {
    serviceId = process.env[serviceIdKey];
    serverUrl = process.env[serverUrlKey];
    if (serverUrl) {
        if (checkUrl(serverUrl)) {
            if (serverUrl.slice(-1) !== '/') {
                serverUrl += '/';
            }
            resolveFn(configKey, serverUrl);
        } else {
            errFn(serverUrlKey + " must be a standard URL: 'http[s]://host[:port]/, current value: " + serverUrl);
        }
    } else if (protocol && serviceId) {
        dns.resolve(serviceId, 'SRV', function onResolve(err, addresses) {
            if (err) {
                errFn('Error during resolving ' + serviceIdKey + ':' + serviceId + ': ' + err);
            } else if (!addresses || addresses.length == 0) {
                errFn(serviceIdKey + ':' + serviceId + ' cannot be resolved!');
            } else {
                resolveFn(configKey, protocol + "://" + addresses[0].name + ":" + addresses[0].port + "/");
            }
        });
    } else {
        errFn(serviceIdKey + ' or ' + serverUrlKey + ' must be specified!');
    }
}
Example #6
0
exports.get_a_records = function (host, cb) {
    var plugin = this;

    if (!/\./.test(host)) {
        // a single label is not a host name
        var e = new Error("invalid hostname");
        e.code = 'ENOTFOUND';
        return cb(e);
    }

    // Set-up timer
    var timer = setTimeout(function () {
        var e = new Error('timeout resolving: ' + host);
        e.code = 'ETIMEOUT';
        plugin.logerror(e);
        return cb(e);
    }, (plugin.cfg.main.dns_timeout || 30) * 1000);

    // fully qualify, to ignore any search options in /etc/resolv.conf
    if (!/\.$/.test(host)) { host = host + '.'; }

    // do the queries
    dns.resolve(host, function(err, ips) {
        if (timer) clearTimeout(timer);
        if (err) return cb(err, ips);
        // plugin.logdebug(plugin, host + ' => ' + ips);
        // return the DNS results
        return cb(null, ips);
    });
};
 it('dns.resolve(' + url.parse(AppcCoverage.SERVER).host + ')', function (done) {
     dns.resolve(url.parse(AppcCoverage.SERVER).host, function (err, addresses) {
         test.assert(err == null, err);
         test.assert(addresses.length > 0, 'No addresses found');
         done();
     });
 });
												(function(port) {
													dns.resolve(servers[i]['@'].host, function(err, addresses) {
														if(!err) {
															self.jingle.push({host: addresses[0], udp: port});
														}
													});
												})(servers[i]['@'].udp);
 addresses.forEach(function (addr) {
     // Handle MX records that are IP addresses
     // This is invalid - but a lot of MTAs allow it.
     if (/^\d+\.\d+\.\d+\.\d+$/.test(addr.exchange)) {
        connection.logwarn(plugin, domain + ': invalid MX ' + addr.exchange);
        if (config.main.allow_mx_ip) {
            a_records[addr.exchange] = 1;
        }
        return;
     } 
     pending_queries++;
     dns.resolve(addr.exchange, function(err, addresses) {
         pending_queries--;
         if (err) {
             results.add(plugin, {err: err.message});
             connection.logdebug(plugin, domain + ': MX ' + addr.priority + ' ' +
                             addr.exchange + ' => ' + err.message);
         }
         else {
             connection.logdebug(plugin, domain + ': MX ' + addr.priority + ' ' +
                             addr.exchange + ' => ' + addresses);
             for (var i=0; i < addresses.length; i++) {
                 // Ignore anything obviously bogus
                 if (re_bogus_ip.test(addresses[i])) {
                     connection.logdebug(plugin, addr.exchange + ': discarding ' + addresses[i]);
                     continue;
                 }
                 a_records[addresses[i]] = 1;
             }
         }
         if (pending_queries === 0) {
             check_results();
         }
     });
 });
Example #10
0
  function sockSend(err, bytes) {
    if (err) {
      log.add('Socket error.');
      log.add(err);
      self.endRequest(res, log, 'system_error');
      return;
    }

    serv = {
      active: false,
      sid: sid,
      addr: addr,
      port: port,
      ver: q.ver,
      desc: q.desc,
      dev: !!q.devbuild,
      ip: addr,
      log: log,
      last: undefined
    };

    // Tallennetaan serveri listaan, jos kaikki meni kuten piti
    self.servers.push(serv);

    // Muunnetaan osoite ip:ksi, jotta sitä voidaan verrata saapuviin UDP-paketteihin.
    dns.resolve(addr, function (err, ip) {
      if (!err) { serv.ip = ip[0]; }
    });
  });
exports.implicit_mx = function (connection, domain, mxDone) {
    var plugin = this;
    var txn = connection.transaction;
    dns.resolve(domain, 'A', function(err, addresses) {
        if (!txn) return;
        if (err && plugin.mxErr(connection, domain, 'A', err, mxDone)) return;

        if (!addresses || !addresses.length) {
            txn.results.add(plugin, {fail: 'has_a_records'});
            return mxDone(((plugin.cfg.main.reject_no_mx) ? DENY : DENYSOFT),
                    'No MX for your FROM address');
        }

        connection.logdebug(plugin, domain + ': A => ' + addresses);
        var a_records = {};
        for (var i=0; i < addresses.length; i++) {
            var addr = addresses[i];
            // Ignore anything obviously bogus
            if (plugin.re_bogus_ip.test(addr)) {
                connection.logdebug(plugin, domain + ': discarding ' + addr);
                continue;
            }
            a_records[addr] = true;
        }

        a_records = Object.keys(a_records);
        if (a_records && a_records.length) {
            txn.results.add(plugin, {pass: '******'});
            return mxDone();
        }

        txn.results.add(plugin, {fail: 'implicit_mx('+domain+')'});
        return mxDone();
    });
};
Example #12
0
function resolve(name, cb) {
        dns.resolve(name, 'AAAA', function(err, addresses) {
            if(err || !addresses) return console.log('[%%%%%%] didn\'t resolve', err);
            console.log('[ % ] resolved to %s', addresses);
            cb(addresses[0]);
        });
};
Example #13
0
app.get('/DNS/:method/:id', function (req, res) {
	var attrIP = req.params.id;
	var method = req.params.method;
	attrIP = attrIP.toString();
	method = method.toString().toUpperCase();
	if (method == "PTR" && !net.isIP(attrIP)) {
		res.json({
			"datetime": Date(),
			"method": method,
			"host": attrIP,
			"err": {
				code: 'BADFAMILY'
			},
			"ipv": (net.isIP(attrIP) ? (net.isIPv6(attrIP) ? 6 : 4) : 0),
			"query": req.query
		});
	} else
		dns.resolve(attrIP, method, function (err, domains) {
			res.json({
				"datetime": Date(),
				"method": method,
				"host": attrIP,
				"result": domains,
				"err": err,
				"ipv": (net.isIP(attrIP) ? (net.isIPv6(attrIP) ? 6 : 4) : 0),
				"query": req.query
			});
		});
});
Example #14
0
 prepareDns(DnsServer.testResolveA(ip), function() {
   dns.resolve("vertx.io", function(err, addresses) {
     vassert.assertTrue("Unexpected error: " + err, err === null);
     vassert.assertTrue("Address should not be null", addresses !== null);
     vassert.assertTrue("Unexpected address: " + addresses, ip === addresses[0]);
     vassert.testComplete();
   });
 });
 helper.runInTransaction(agent, function() {
   dns.resolve('example.com', function(err, ips) {
     t.notOk(err, 'should not error')
     t.equal(ips.length, 1)
     t.ok(ips[0].match(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/))
     verifySegments(t, agent, 'dns.resolve', ['dns.resolve4'])
   })
 })
Example #16
0
 it('should create resolve cache with type', function (done) {
     dns.resolve('www.yahoo.com', 'A', function(err, result) {
         assert.ok(dns.internalCache);
         assert.ok(result);
         assert.equal(dns.internalCache.data['resolve_www.yahoo.com_A'].hit, 0, 'hit should be 0 for resolve');
         done();
     });
 });
Example #17
0
 checkNetwork: function(callback) {
     dns.resolve(coim_config.coim_app_code + '.coimapi.tw', function(err) {
              if (err)
                 callback(false);
              else
                 callback(true);
              });
 },
Example #18
0
 prepareDns(DnsServer.testResolveNS(ns), function() {
   dns.resolve("vertx.io", 'NS', function(err, records) {
     vassert.assertTrue("Unexpected number of response records: " + records.length, 
       1 === records.length);
     vassert.assertTrue("Unexpected result: " + records[0], ns === records[0]);
     vassert.testComplete();
   });
 });
Example #19
0
 prepareDns(DnsServer.testResolveMX(prio, name), function() {
   dns.resolve("vertx.io", 'MX', function(err, records) {
     vassert.assertTrue("Unexpected error: " + err, err === null);
     vassert.assertTrue("Unexpected priority: " + records[0], prio == records[0].priority);
     vassert.assertTrue("Unexpected exchange: " + records[0], name === records[0].exchange);
     vassert.testComplete();
   });
 });
Example #20
0
IPInfo.prototype.getDNS = function(msg) {
	dns.resolve( msg.match_data[2], function (err, address) {
		if (err) throw err;

		// first result is as good as any.
		msg.say(msg.user + ": " + msg.match_data[2] + " = " + address[0]);
	});
	
};
Example #21
0
  connect() {
    dns.resolve(this.remotehost, (err, servers) => {
      if (err || !servers[0])
        return this._error(`Could not resolve name '${this.remotehost}'`);

      this.remoteip = servers[0];
      this._connect();
    });
  }
Example #22
0
// Récupère l'addresse ip d'un serveur selon un nom de domaine donné
function getDnsResolve(domain, res, callback) {
    dns.resolve(domain, 'A', function (err, addresses) {
        if (err)
            res.send(err);
        else {
            callback(addresses);
        }
    });
}
Example #23
0
function getDns(postData, callback) {
    var domain = querystring.parse(postData).search_dns;
    dns.resolve(domain, function(err, addresses) {
        if (!addresses) {
            addresses = ['不存在域名'];
        }
        callback(domain, addresses);
    });
}
Example #24
0
 // connects to a random TCP peer via a random DNS seed
 // (selected from `dnsSeeds` in the params)
 _connectDNSPeer (cb) {
   var seeds = this._params.dnsSeeds
   var seed = utils.getRandom(seeds)
   dns.resolve(seed, (err, addresses) => {
     if (err) return cb(err)
     var address = utils.getRandom(addresses)
     this._connectTCP(address, this._params.defaultPort, cb)
   })
 }
Example #25
0
  operation.attempt(function(currentAttempt) {
    dns.resolve(address, function(err, addresses) {
      if (operation.retry(err)) {
        return;
      }

      cb(operation.mainError(), operation.errors(), addresses);
    });
  });
Example #26
0
File: rbl.js Project: MaxCDN/iptell
function blacklistedTarget(ip, target, cb) {
    dns.resolve(reverseIp(ip) + '.' + target.dns, function(err, data) {
        if(err) {
            // errors in case there is no match or the service is down
            return cb(null);
        }

        cb(null, target);
    });
}
Example #27
0
function checkDns(address, cb){
	dns.resolve(address, function(err, addresses){
		if (err) return cb(err);
		for (var i = 0; i < addresses.length; i++){
			var result = checkIp(addresses[i], address);
			if (result) return cb(null, result);
		}
		cb(null, false);
	});
}
 // iterator function
 function (rrtype, callback) {
     console.log("Looking up %s records for [%s]", rrtype, hostname);
     
     // do a DNS resolve of this record type
     dns.resolve(hostname, rrtype, function (err, addresses) {
         console.log("\t%s\n\t%s", rrtype, JSON.stringify(addresses));
         records[rrtype] = addresses;
         
         callback();
     })
 },
Example #29
0
	function getDns(postData,callback){
		var domain = querystring.parse(postData).dns;
		//querystring.parse:将字符串转化为对象
		dns.resolve(domain,function(err,addresses){
			if(!addresses){
				addresses = ['不存在域名'];
			}
			callback(domain,addresses);
		});
		//dns.resolve:将域名(比如'google.com')按照参数rrtype所指定类型的解析结果放到一个数组中,回调函数接受两个参数:(err, addresses)
	}
Example #30
0
 prepareDns(DnsServer.testResolveSRV(prio, weight, port, target), function() {
   dns.resolve("vertx.io", 'SRV', function(err, records) {
     vassert.assertNotNull(records);
     record = records[0];
     vassert.assertTrue("Unexpected value: " + record.priority, prio == record.priority);
     vassert.assertTrue("Unexpected value: " + record.weight, weight == record.weight);
     vassert.assertTrue("Unexpected value: " + record.port, port == record.port);
     vassert.assertTrue("Unexpected address: " + record.target, target === record.target);
     vassert.testComplete();
   });
 });