From b32102ec99e70af498c20df2484c2949ff0ecd5d Mon Sep 17 00:00:00 2001 From: atrax <atrax@prtn.email> Date: Mon, 28 Dec 2020 22:37:36 +0100 Subject: [PATCH] [mod] #226: Use DuniterPy's regex instead of ipaddress --- silkaj/network_tools.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/silkaj/network_tools.py b/silkaj/network_tools.py index b3b9ea9f..d269ae52 100644 --- a/silkaj/network_tools.py +++ b/silkaj/network_tools.py @@ -16,13 +16,14 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. """ from __future__ import unicode_literals -from ipaddress import ip_address +import re import socket import logging from sys import exit, stderr from asyncio import sleep from duniterpy.api.client import Client from duniterpy.api.bma import network +from duniterpy.constants import IPV4_REGEX, IPV6_REGEX from silkaj.constants import ( G1_DEFAULT_ENDPOINT, @@ -198,10 +199,11 @@ def endpoint_type(sep, ep): def check_ip(address): - try: - return ip_address(address).version - except: - return 0 + if re.match(IPV4_REGEX, address) != None: + return 4 + elif re.match(IPV6_REGEX, address) != None: + return 6 + return 0 def best_endpoint_address(ep, main): -- GitLab