Quellcode durchsuchen

Parse raw IPs and hostnames in the block monitor.

pull/10/merge
Ben Kurtovic vor 8 Jahren
Ursprung
Commit
5d5e05d33c
1 geänderte Dateien mit 13 neuen und 5 gelöschten Zeilen
  1. +13
    -5
      commands/block_monitor.py

+ 13
- 5
commands/block_monitor.py Datei anzeigen

@@ -21,6 +21,7 @@
# SOFTWARE.

import re
from socket import gaierror, gethostbyname
from time import time

from earwigbot.commands import Command
@@ -46,12 +47,9 @@ class BlockMonitor(Command):
data.chan == self._monitor_chan)

def process(self, data):
if not data.host.startswith("gateway/web/"):
ip = self._get_ip(data.host)
if not ip:
return
match = re.search(r"/ip\.(.*?)$", data.host)
if not match:
return
ip = match.group(1)

if self._last and self._last[0] == ip:
if time() - self._last[1] < 60 * 5:
@@ -71,6 +69,16 @@ class BlockMonitor(Command):
"{type}blocked because: {reason}")
self.logger.info(log.format(nick=data.nick, **block))

def _get_ip(self, host):
"""Return the IP corresponding to a particular hostname."""
match = re.search(r"/ip\.(.*?)$", host)
if match:
return match.group(1)
try:
return gethostbyname(host)
except gaierror:
return None

def _get_block_for_ip(self, ip):
"""Return a dictionary of blockinfo for an IP."""
site = self.bot.wiki.get_site()


Laden…
Abbrechen
Speichern