From 3a16fb46a16f91557f6805e74aafb568f46fd1c0 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 6 Dec 2019 19:32:09 +0100 Subject: Python/VyOS validate: T1849: handle is_ipv6()/is_ipv6() exceptions --- python/vyos/validate.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'python/vyos') diff --git a/python/vyos/validate.py b/python/vyos/validate.py index 258f7f76a..3f3166022 100644 --- a/python/vyos/validate.py +++ b/python/vyos/validate.py @@ -29,10 +29,13 @@ def is_ipv4(addr): # With the below statement we can check for IPv4 networks and host # addresses at the same time - if ipaddress.ip_address(addr.split(r'/')[0]).version == 4: - return True - else: - return False + try: + if ipaddress.ip_address(addr.split(r'/')[0]).version == 4: + return True + except: + pass + + return False def is_ipv6(addr): """ @@ -41,10 +44,13 @@ def is_ipv6(addr): # With the below statement we can check for IPv4 networks and host # addresses at the same time - if ipaddress.ip_network(addr.split(r'/')[0]).version == 6: - return True - else: - return False + try: + if ipaddress.ip_network(addr.split(r'/')[0]).version == 6: + return True + except: + pass + + return False def is_intf_addr_assigned(intf, addr): """ -- cgit v1.2.3