From 75dd3e5b1d50fb69e8a824d80adc7dc1de9ed45d Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Wed, 29 Jun 2022 17:23:23 +0200 Subject: [PATCH] Added a function to check if an IP is local --- src/utils/network.py | 7 +++++++ src/utils/yunopaste.py | 14 ++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/utils/network.py b/src/utils/network.py index 134b23909..d1892483e 100644 --- a/src/utils/network.py +++ b/src/utils/network.py @@ -30,6 +30,13 @@ from moulinette.utils.process import check_output from yunohost.settings import settings_get logger = logging.getLogger("yunohost.utils.network") + +def is_ip_local(ip): + """Returns True if the provided Ip is local""" + filters = ["192.168", "172.16.", "10."] + for filter in filters: + if ip.startswith(filter): + return True def get_public_ip(protocol=4): diff --git a/src/utils/yunopaste.py b/src/utils/yunopaste.py index 694c709d1..40ad73fdd 100644 --- a/src/utils/yunopaste.py +++ b/src/utils/yunopaste.py @@ -7,6 +7,7 @@ import re from yunohost.domain import _get_maindomain, domain_list from yunohost.utils.error import YunohostError +from yunohost.utils.network import is_ip_local logger = logging.getLogger("yunohost.utils.yunopaste") @@ -89,18 +90,7 @@ def anonymize(data): ipsv6 = re.findall(ipv6regex, data) # Filter local IPs - filters = ["192.168", "172.16.", "10."] - i = 0 - while i