Improve(?) IPv6 regex

This commit is contained in:
jesopo 2018-10-04 13:19:59 +01:00
parent 26b653555b
commit 6b122523c0

View file

@ -2,7 +2,7 @@ import re, socket
from src import ModuleManager, utils from src import ModuleManager, utils
URL_GEOIP = "http://ip-api.com/json/%s" URL_GEOIP = "http://ip-api.com/json/%s"
REGEX_IP = ("(?:\b|\s|^)((?:(?:[a-f0-9]{1,4}:){2,}|::)[^\s]+)(?:\b|\s|$)" # ipv6 REGEX_IP = ("((?:(?:[a-f0-9]{1,4}:){2,}|[a-f0-9:]*::)[a-f0-9:]*)" # ipv6
"|" "|"
"((?:\d{1,3}\.){3}\d{1,3})") # ipv4 "((?:\d{1,3}\.){3}\d{1,3})") # ipv4
REGEX_IP = re.compile(REGEX_IP, re.I) REGEX_IP = re.compile(REGEX_IP, re.I)
@ -77,4 +77,4 @@ class Module(ModuleManager.BaseModule):
except (socket.herror, socket.gaierror) as e: except (socket.herror, socket.gaierror) as e:
event["stderr"].write(e.strerror) event["stderr"].write(e.strerror)
return return
event["stdout"].write("%s: %s" % (ips[0], hostname)) event["stdout"].write("(%s) %s" % (ips[0], hostname))