diff options
| author | Alex W <embezzle.dev@proton.me> | 2025-01-30 20:22:41 +0000 |
|---|---|---|
| committer | Alex W <embezzle.dev@proton.me> | 2025-03-21 21:08:50 +0100 |
| commit | 9e2bdc96ea63e7ee1adb002df17e0d9ecc1cd410 (patch) | |
| tree | 29af39c615a3b3cbcf327af4839f578f29af00d9 /python/vyos/utils/network.py | |
| parent | 7eec4583bf7feb900fad02e009b9ded11b52fd5d (diff) | |
| download | veeos-1x-9e2bdc96ea63e7ee1adb002df17e0d9ecc1cd410.tar.gz veeos-1x-9e2bdc96ea63e7ee1adb002df17e0d9ecc1cd410.zip | |
firewall: T5493: Implement remote-group
Diffstat (limited to 'python/vyos/utils/network.py')
| -rw-r--r-- | python/vyos/utils/network.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py index dc0c0a6d6..2f666f0ee 100644 --- a/python/vyos/utils/network.py +++ b/python/vyos/utils/network.py @@ -599,3 +599,19 @@ def get_nft_vrf_zone_mapping() -> dict: for (vrf_name, vrf_id) in vrf_list: output.append({'interface' : vrf_name, 'vrf_tableid' : vrf_id}) return output + +def is_valid_ipv4_address_or_range(addr: str) -> bool: + """ + Validates if the provided address is a valid IPv4, CIDR or IPv4 range + :param addr: address to test + :return: bool: True if provided address is valid + """ + from ipaddress import ip_network + try: + if '-' in addr: # If we are checking a range, validate both address's individually + split = addr.split('-') + return is_valid_ipv4_address_or_range(split[0]) and is_valid_ipv4_address_or_range(split[1]) + else: + return ip_network(addr).version == 4 + except: + return False |
