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

import sys
import re

if __name__ == '__main__':
    if len(sys.argv)>1:
        port_range = sys.argv[1]
        if re.search('[0-9]{1,5}-[0-9]{1,5}', port_range):
            for tmp in port_range.split('-'):
                if int(tmp) not in range(1, 65535):
                    print(f'Error: {port_range} is not a valid port range')
                    sys.exit(1)
        else:
            if int(port_range) not in range(1, 65535):
                print(f'Error: {port_range} is not a valid port')
                sys.exit(1)
    else:
        sys.exit(2)

    sys.exit(0)