summaryrefslogtreecommitdiff
path: root/src/validators/ipv6-range
blob: 7080860c4c4c74001496e334ce54347ffe9057bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3

from ipaddress import IPv6Address
from sys import argv, exit

if __name__ == '__main__':
    if len(argv) > 1:
        # try to pass validation and raise an error if failed
        try:
            ipv6_range = argv[1]
            range_left = ipv6_range.split('-')[0]
            range_right = ipv6_range.split('-')[1]
            if not IPv6Address(range_left) < IPv6Address(range_right):
                raise ValueError(f'left element {range_left} must be less than right element {range_right}')
        except Exception as err:
            print(f'Error: {ipv6_range} is not a valid IPv6 range: {err}')
            exit(1)
    else:
        print('Error: an IPv6 range argument must be provided')
        exit(1)