瀏覽代碼

Parse raw IPs and hostnames in the block monitor.

pull/10/merge
Ben Kurtovic 8 年之前
父節點
當前提交
5d5e05d33c
共有 1 個檔案被更改,包括 13 行新增5 行删除
  1. +13
    -5
      commands/block_monitor.py

+ 13
- 5
commands/block_monitor.py 查看文件

@@ -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()


Loading…
取消
儲存