iwla

iwla Git Source Tree

Root/plugins/post_analysis/reverse_dns.py

1import socket
2
3from iwla import IWLA
4from iplugin import IPlugin
5
6#
7# Post analysis hook
8#
9# Replace IP by reverse DNS names
10#
11# Plugin requirements :
12# None
13#
14# Conf values needed :
15# reverse_dns_timeout*
16#
17# Output files :
18# None
19#
20# Statistics creation :
21# None
22#
23# Statistics update :
24# valid_visitors:
25# remote_addr
26# dns_name_replaced
27# dns_analyzed
28#
29# Statistics deletion :
30# None
31#
32
33class IWLAPostAnalysisReverseDNS(IPlugin):
34 DEFAULT_DNS_TIMEOUT = 0.5
35
36 def __init__(self, iwla):
37 super(IWLAPostAnalysisReverseDNS, self).__init__(iwla)
38 self.API_VERSION = 1
39
40 def load(self):
41 timeout = self.iwla.getConfValue('reverse_dns_timeout',
42 IWLAPostAnalysisReverseDNS.DEFAULT_DNS_TIMEOUT)
43 socket.setdefaulttimeout(timeout)
44 return True
45
46 def hook(self):
47 hits = self.iwla.getValidVisitors()
48 for (k, hit) in hits.items():
49 if hit.get('dns_analysed', False): continue
50 try:
51 name, _, _ = socket.gethostbyaddr(k)
52 hit['remote_addr'] = name
53 hit['dns_name_replaced'] = True
54 except:
55 pass
56 finally:
57 hit['dns_analysed'] = True
58

Archive Download this file

Branches

Tags