forked from node-pcap/node_pcap
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns_cache.js
More file actions
Latest commit
35 lines (28 loc) · 789 Bytes
/
Copy pathdns_cache.js
File metadata and controls
35 lines (28 loc) · 789 Bytes
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
vardns=require("dns");
// cache reverse DNS lookups for the life of the program. No TTL checking. No tricks.
functionDNSCache(){
this.cache={};
this.requests={};
}
DNSCache.prototype.ptr=function(ip){
if(this.cache[ip]){
returnthis.cache[ip];
}
if(this.requests[ip]===undefined){
this.requests[ip]=true;
varself=this;
dns.reverse(ip,function(err,domains){
self.on_ptr(err,ip,domains);
});
}
returnip;
};
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;