diff --git a/moesifwsgi/client_ip.py b/moesifwsgi/client_ip.py index f8d889c..bf371d0 100644 --- a/moesifwsgi/client_ip.py +++ b/moesifwsgi/client_ip.py @@ -1,5 +1,6 @@ import re import logging +import ipaddress logger = logging.getLogger(__name__) @@ -10,10 +11,12 @@ def __init__(self): @classmethod def is_ip(cls, value): - if not value is None: - ipv4 = r"^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$" - ipv6 = r"^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i" - return re.match(ipv4, value) or re.match(ipv6, value) + # https://docs.python.org/3/library/ipaddress.html#ipaddress.ip_address + try: + ip = ipaddress.ip_address(value) + return True + except ValueError: + return False def getClientIpFromXForwardedFor(self, value): try: @@ -98,4 +101,4 @@ def get_client_address(self, environ): return environ['REMOTE_ADDR'] except KeyError: - return environ['REMOTE_ADDR'] \ No newline at end of file + return environ['REMOTE_ADDR'] diff --git a/moesifwsgi/middleware.py b/moesifwsgi/middleware.py index e41df0d..4b5b35a 100644 --- a/moesifwsgi/middleware.py +++ b/moesifwsgi/middleware.py @@ -104,7 +104,7 @@ def initialize_config(self): response_catcher = HttpResponseCatcher(self.DEBUG) self.api_client.http_call_back = response_catcher Configuration.BASE_URI = self.settings.get("BASE_URI") or self.settings.get("LOCAL_MOESIF_BASEURL", "https://api.moesif.net") - Configuration.version = "moesifwsgi-python/1.9.6" + Configuration.version = "moesifwsgi-python/1.9.7" if self.settings.get("CAPTURE_OUTGOING_REQUESTS", False): StartCapture().start_capture_outgoing(self.settings) diff --git a/setup.py b/setup.py index 2f0c824..21c2b5a 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='1.9.6', + version='1.9.7', description='Moesif Middleware for Python WSGI based platforms (Flask, Bottle & Others)', long_description=long_description, @@ -49,7 +49,7 @@ # 3 - Alpha # 4 - Beta # 5 - Production/Stable - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', # Indicate who your project is intended for 'Intended Audience :: Developers',