iwla

iwla Git Source Tree

Root/plugins/post_analysis/reverse_dns.py

Source at commit 4e02325733e5e8e4f5de2f0046e721f8da7abfff created 6 years 10 months ago.
By Gregory Soutade, Initial commit
1# -*- coding: utf-8 -*-
2#
3# Copyright Grégory Soutadé 2015
4
5# This file is part of iwla
6
7# iwla is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# iwla is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with iwla. If not, see <http://www.gnu.org/licenses/>.
19#
20
21import socket
22
23from iwla import IWLA
24from iplugin import IPlugin
25
26"""
27Post analysis hook
28
29Replace IP by reverse DNS names
30
31Plugin requirements :
32 None
33
34Conf values needed :
35 reverse_dns_timeout*
36
37Output files :
38 None
39
40Statistics creation :
41 None
42
43Statistics update :
44valid_visitors:
45 remote_addr
46 dns_name_replaced
47 dns_analyzed
48
49Statistics deletion :
50 None
51"""
52
53class IWLAPostAnalysisReverseDNS(IPlugin):
54 DEFAULT_DNS_TIMEOUT = 0.5
55
56 def __init__(self, iwla):
57 super(IWLAPostAnalysisReverseDNS, self).__init__(iwla)
58 self.API_VERSION = 1
59
60 def load(self):
61 timeout = self.iwla.getConfValue('reverse_dns_timeout',
62 IWLAPostAnalysisReverseDNS.DEFAULT_DNS_TIMEOUT)
63 socket.setdefaulttimeout(timeout)
64 return True
65
66 def hook(self):
67 hits = self.iwla.getValidVisitors()
68 for (k, hit) in hits.items():
69 if hit.get('dns_analysed', False): continue
70 try:
71 name, _, _ = socket.gethostbyaddr(k)
72 hit['remote_addr'] = name.lower()
73 hit['dns_name_replaced'] = True
74 except:
75 pass
76 finally:
77 hit['dns_analysed'] = True
78

Archive Download this file

Branches

Tags