diff options
| author | Daniil Baturin <daniil@vyos.io> | 2025-03-25 15:20:48 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-25 15:20:48 +0000 |
| commit | 1c66841323ba1fa4f90d3ce3de6ef7cebc07ed97 (patch) | |
| tree | 91c8431c6b5f238d9251177ff0ee1985ad29aef6 /python/vyos/utils/network.py | |
| parent | 3fee8ec30dce8f3987fe468d29109ed4e1bc492a (diff) | |
| parent | 9e2bdc96ea63e7ee1adb002df17e0d9ecc1cd410 (diff) | |
| download | veeos-1x-1c66841323ba1fa4f90d3ce3de6ef7cebc07ed97.tar.gz veeos-1x-1c66841323ba1fa4f90d3ce3de6ef7cebc07ed97.zip | |
Merge pull request #4326 from Embezzle/T5493
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 |
