http.createServer(function(req, res) { var remoteAddress = (req.headers['x-forwarded-for'] || '').split(',')[0] || req.connection.remoteAddress; switch(req.url){ case "/": dns.reverse(remoteAddress, function(err, domains){ res.writeHead(200, {'Content-Type': 'text/html'}); res.end(cachedFrontpage.replace(/%RESPONSE%/, JSON.stringify({ address: remoteAddress, hostname: domains && domains[0] || false }, false, 4))); }); break; case "/api/ip": dns.reverse(remoteAddress, function(err, domains){ res.writeHead(200, {'Content-Type': 'application/json'}); res.end(JSON.stringify({ address: remoteAddress, hostname: domains && domains[0] || undefined }, false, 4) + "\n"); }); break; default: res.writeHead(200, {'Content-Type': 'text/html'}); res.end(cached404); break; } }).listen(port, ip, function(){
this.getOwnHostnames = function(callback) { if (!self.IPs) { return process.nextTick(function(){ callback('Missing IPs', null); }); } else if (options.domains) { return process.nextTick(function(){ callback(null, options.domains); }); } var ips = Object.keys(self.IPs); options.domains = options.domains || {}; var onReady = self.whenAllDone.bind(self, {todo: ips.length}, function(){ self.emit('domainsResolved', options.domains); callback(null, options.domains); }); var onDomains = function domainsReceived(ip, error, domains) { if (!error) { for (var i = 0; i < domains.length; i++) { options.domains[domains[i]] = ip; } } onReady(); }; for (var i = 0; i < ips.length; i++) { dns.reverse(ips[i], onDomains.bind(self, ips[i])); } };
helper.runInTransaction(agent, function() { dns.reverse('127.0.0.1', function(err, names) { t.notOk(err, 'should not error') t.deepEqual(names, []) verifySegments(t, agent, 'dns.reverse') }) })
self.context.zk.a_get_children(CACHE_SERVER_MAPPING+'/'+e, false, function(rc, err, path) { if (static_map[path] == null) { static_map[path] = {}; } var ipport = e.split(':'); var ip = ipport[0]; var port = ipport.length > 1 ? ipport[1] : null; dns.reverse(ip, function(err, domains) { if (err) { _.defaults(static_map[path], {"servers":{}, "hubble":hubble[path], "port":port}); // if there's an service code with a port, it should be a private cloud. if (static_map[path].servers[ip]) { port = null; } static_map[path].servers[ip] = {ip:ip, port:port}; static_ipport_map[port ? ip+':'+port : ip] = path; } else { _.defaults(static_map[path], {"servers":{}, "hubble":hubble[path], "port":port}); // if there's an service code with a port, it should be a private cloud. if (static_map[path].servers[domains[0]]) { port = null; } static_map[path].servers[domains[0]] = {ip:ip, port:port}; static_ipport_map[port ? ip+':'+port : ip] = path; static_ipport_map[port ? domains[0]+':'+port : domains[0]] = path; } cb(null, 'OK'); }); });
function setupClient(self) { self.remote_ip = self.client.remoteAddress; self.lognotice("got connection from: " + self.remote_ip); self.client.on('error', function (err) { if (!self.disconnected) { self.fail("client closed with err: " + err); } }); self.client.on('timeout', function () { if (!self.disconnected) { self.fail("client (" + self.client.fd + ") timed out"); } }); self.client.on('data', function (data) { self.process_data(data); }); dns.reverse(self.remote_ip, function(err, domains) { if (err) { switch (err.code) { case dns.NXDOMAIN: self.remote_host = 'NXDOMAIN'; break; default: self.remote_host = 'DNSERROR'; break; } } else { self.remote_host = domains[0] || 'Unknown'; } self.remote_info = self.remote_info || self.remote_host; plugins.run_hooks('connect', self); }); }
exec('curl ifconfig.me', function (err, stdout, stderr) { console.log('stdout:' + stdout); var addr = '' + stdout dns.reverse('54.224.72.30', function(err, domain) { console.log( domain ); }); });
Connection.prototype.lookup_rdns_respond = function (retval, msg) { var self = this; switch(retval) { case constants.ok: this.remote_host = msg || 'Unknown'; this.remote_info = this.remote_info || this.remote_host; plugins.run_hooks('connect', this); break; case constants.deny: this.loop_respond(554, msg || "rDNS Lookup Failed"); break; case constants.denydisconnect: case constants.disconnect: this.respond(554, msg || "rDNS Lookup Failed", function () { self.disconnect(); }); break; case constants.denysoft: this.loop_respond(421, msg || "rDNS Temporary Failure"); break; case constants.denysoftdisconnect: this.respond(421, msg || "rDNS Temporary Failure", function () { self.disconnect(); }); break; default: var self = this; dns.reverse(this.remote_ip, function(err, domains) { self.rdns_response(err, domains); }) } }
_reverseDns(ip, callback) { if (!this.options.reverse) { return callback(); } if (this.cacheDns[ip]) { return callback(null, this.cacheDns[ip]); } dns.reverse(ip, (err,domains) => { if (err) { if (err.code == 'ENOTFOUND') { return cb(null); } // unknow error this.emit('error',{ fnc:'lookupDns', err:err }); return callback(null); } if (!domains.length) { return callback(null); } callback(null, domains[0]); }); }
var Slave = function (socket, data, config, logger) { this.id = data.id; this.slaveNumber = ++slaveCounter; this.logger = new Logger("Slave", this.slaveNumber, logger); this.config = config; this.socket = socket; this.userAgent = data.userAgent; this.browserInfo = detectBrowser(data); this.displayName = this.browserInfo.displayName; this.address = socket.remoteAddress; this.port = socket.remotePort; this.addressName = null; // set by onReceiveAddressName this.taskExecutionId = null; this.currentTask = null; this.currentCampaign = null; this.paused = !!data.paused; this.taskTimeoutId = null; this.idle = false; // matchingCampaignBrowsers is an array of objects containing a campaign and // a browser properties, it is updated by the test server when a campaign is // added or removed, and when a slave is added or removed this.matchingCampaignBrowsers = []; dns.reverse(this.address, this.onReceiveAddressName.bind(this)); socket.on('data', this.onSocketData.bind(this)); socket.on('close', this.onSocketDisconnected.bind(this)); };
get('/', function () { var self = this, address = self.headers['x-real-ip'] || self.socket.remoteAddress; if(!self.session.name){ dns.reverse(address, function (err, name) { if (address === '127.0.0.1') { name = 'kingofpain'; } else if (err !== null) { name = 'Unknown'; } // trim off the CMASS stuff var shortName = name.toString().split('.')[0]; // slice off the dash and machine type (if it exists) shortName = shortName.split('-')[0]; self.session.name = shortName; }); } this.pass('/vote'); });
prepareDns(DnsServer.testReverseLookup(ptr), function() { dns.reverse('::1', function(err, records) { vassert.assertNotNull(records); vassert.assertTrue("Unexpected address: " + records[0], records[0] === ptr); vassert.testComplete(); }); });
}).cmd('resolve', function(type, err, addresses) { if (err) throw err; for (var i = 0; i < addresses.length; i++) { var adr = addresses[i]; dns.reverse(adr, this.cb('reverse', type, adr)); }; }).cmd('reverse', function(type, adr, err, data) {
robot.hear(/^!rdns (.*)/i, function(msg){ var ip = msg.match[1]; if(ipv4.test(ip) || ipv6.test(ip)){ dns.reverse(ip, function(err, domains){ if(err){ if(err.code == "ENOTFOUND" || err.code == "ENODATA"){ msg.send(host + ": No PTR record found"); }else{ msg.send(ip + ": Lookup error: " + err.code); } }else{ if(domains.length == 0){ msg.send(ip + ": No matching domain found"); }else if(domains.length == 1){ msg.send(ip + ": " + domains[0]); }else{ msg.send(ip + " matches multiple hostnames:"); var out = "/quote "; domains.forEach(function(d){ out += d; out += "\n"; }); msg.send(out.trim()); } } }); }else{ msg.send(ip + " is no valid ipv4 or ipv6 address"); } });
ReverseDNSSource.prototype.getIp = function(ip, cb) { if (!this.trie.find(ip)) { return cb(null, undefined); } dns.reverse(ip, (err, domains) => { //console.log("answer", ip, err, domains); if (err || domains.length === 0) { return cb(null, wiseSource.emptyResult); } var args = []; for (var i = 0; i < domains.length; i++) { var domain = domains[i]; if (this.stripDomains.length === 0) { var parts = domain.split("."); args.push(this.theField, parts[0].toLowerCase()); } else { for (var j = 0; j < this.stripDomains.length; j++) { var stripDomain = this.stripDomains[j]; if (domain.indexOf(stripDomain, domain.length - stripDomain.length) !== -1) { args.push(this.theField, domain.slice(0, domain.length - stripDomain.length)); } } } } var wiseResult = {num: args.length/2, buffer: wiseSource.encode.apply(null, args)}; cb(null, wiseResult); }); };
var resolveRemoteHostname = function(callback) { dns.reverse(req.connection.remoteAddress, function(err, domains) { // Swallow any errors, no remote hostname ain't the end of the world. req.ctx.remoteHost = !err ? domains.shift() : ""; callback(); }); }.bind(this);
hostLookup: function() { if (!this.remoteAddress) return; user = this; dns.reverse(this.remoteAddress, function(err, addresses) { user.hostname = addresses && addresses.length > 0 ? addresses[0] : user.remoteAddress; }); },
evilscan.prototype.lookupDns = function(ip,cb) { var self = this; if (!this.options.reverse) return cb(); if (this.cacheDns[ip]) { return cb(null,this.cacheDns[ip]); } dns.reverse(ip,function(err,domains) { if (err) { if (err.code == 'ENOTFOUND') { return cb(null); } else { // unknow error var e = { fnc:'lookupDns', err:err } self.emit('error',e); return cb(null); } } if (!domains.length) return cb(null); cb(null,domains[0]); }); }
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); }); }
function resolve(next) { dns.reverse(address, function (err, hostNames) { if (err) return next(err); if (!hostNames) return next(); name = hostNames[0]; next(); }); },
return function(err, addresses) { if (err) return error(err); for (var i = 0; i < addresses.length; i++) { var adr = addresses[i]; ++count; dns.reverse(adr, reverse(type, adr)); }; }
this.cache_miss = function(key, callback) { try { dns.reverse(key, callback); } catch(e) { callback(e); } };
addresses.forEach((a) => { dns.reverse(a, (err, hostnames) => { if (err) { throw err; } console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`); }); });
exports.hook_lookup_rdns = function (next, connection) { this.load_uri_config(next); var plugin = this; dns.reverse(connection.remote_ip, function (err, rdns) { if (err) return next(); plugin.do_lookups(connection, next, rdns, 'rdns'); }); }
app.get('/revdns/:ip', (req, res) => { dns.reverse(req.params.ip, (err, hostnames) => { if(!hostnames || hostnames.length < 1) { res.send('brak revdns'); } else { res.send(hostnames[0]); } }); });
addresses.forEach(function (a) { dns.reverse(a, function (err, domains) { if (err) { console.error('reverse for ' + a + ' failed: ' + err.message); } else { console.error('reverse for ' + a + ': ' + JSON.stringify(domains)); } }); });
hostLookup() { if (!this.remoteAddress) { return; } dns.reverse(this.remoteAddress, (err, addresses) => { this.hostname = addresses && addresses.length > 0 ? addresses[0] : this.remoteAddress; }); }
function tcpGetDomainName (ip, callback) { dns.reverse (ip, function (err, domains) { if (err != null) { callback (ip); //use the IP address in place of the domain name } else { callback (domains); } }); }
addresses.forEach(function (a) { dns.reverse(a, function (err, domains) { if (err) { throw err; } console.log('reverse for ' + a + ': ' + JSON.stringify(domains)); }); });
dns.lookup('www.github.com',function(err,address,family){ console.log('ip 地址:' + address); dns.reverse(address,function(err,hostnames){ if(err){ console.log(err.stack); } console.log('反向解析 ' + address + ':' + JSON.stringify(hostnames)); }); });
function reverseLookup(ip, dataCallback) { dns.reverse(ip, function (err, domains) { if (err) { dataCallback(ip); } else { dataCallback(ip, domains[0]); } }); }