forked from node-pcap/node_pcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_cache.js
35 lines (28 loc) · 789 Bytes
/
dns_cache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var dns = require("dns");
// cache reverse DNS lookups for the life of the program. No TTL checking. No tricks.
function DNSCache() {
this.cache = {};
this.requests = {};
}
DNSCache.prototype.ptr = function (ip) {
if (this.cache[ip]) {
return this.cache[ip];
}
if (this.requests[ip] === undefined) {
this.requests[ip] = true;
var self = this;
dns.reverse(ip, function (err, domains) {
self.on_ptr(err, ip, domains);
});
}
return ip;
};
DNSCache.prototype.on_ptr = function (err, ip, domains) {
// TODO - check for network and broadcast addrs, since we have iface info
if (err) {
this.cache[ip] = ip;
} else {
this.cache[ip] = domains[0];
}
};
module.exports = DNSCache;