iwla/plugins/post_analysis/reverse_dns.py

80 lines
2.0 KiB
Python
Raw Normal View History

2014-12-18 19:54:31 +01:00
# -*- coding: utf-8 -*-
#
# Copyright Grégory Soutadé 2015
# This file is part of iwla
# iwla is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iwla is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iwla. If not, see <http://www.gnu.org/licenses/>.
#
2014-11-24 21:37:37 +01:00
import socket
from iwla import IWLA
2014-11-24 17:13:59 +01:00
from iplugin import IPlugin
"""
Post analysis hook
Replace IP by reverse DNS names
Plugin requirements :
None
Conf values needed :
reverse_dns_timeout*
Output files :
None
Statistics creation :
None
Statistics update :
valid_visitors:
remote_addr
dns_name_replaced
dns_analyzed
Statistics deletion :
None
"""
2014-12-10 07:09:05 +01:00
2014-11-24 17:13:59 +01:00
class IWLAPostAnalysisReverseDNS(IPlugin):
DEFAULT_DNS_TIMEOUT = 0.5
2014-11-24 21:37:37 +01:00
def load(self):
timeout = self.iwla.getConfValue('reverse_dns_timeout',
IWLAPostAnalysisReverseDNS.DEFAULT_DNS_TIMEOUT)
2014-11-24 21:37:37 +01:00
socket.setdefaulttimeout(timeout)
return True
def hook(self):
hits = self.iwla.getCurrentVisits()
2014-11-24 17:13:59 +01:00
for (k, hit) in hits.items():
if hit.get('dns_analysed', False): continue
# Do reverse for feed parser even if they're not
# valid visitors
2016-08-20 13:08:02 +02:00
if not hit.get('feed_parser', False) and\
2016-01-18 07:33:48 +01:00
not self.iwla.isValidVisitor(hit):
continue
2014-11-24 17:13:59 +01:00
try:
name, _, _ = socket.gethostbyaddr(k)
2014-12-16 07:38:57 +01:00
hit['remote_addr'] = name.lower()
2014-11-26 16:17:16 +01:00
hit['dns_name_replaced'] = True
2014-11-24 17:13:59 +01:00
except:
pass
finally:
hit['dns_analysed'] = True