summaryrefslogtreecommitdiff
path: root/src/validators/packet-length
blob: d96093849548a57c5b7545ac22312e2ec25729b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python3

from sys import argv
from sys import exit
import re

if __name__ == '__main__':
    if len(argv)>1:
        lengths = argv[1].split(",")

        for length in lengths:
            if length and length[0] == '!':
                length = length[1:]
            if re.match('^[0-9]{1,5}-[0-9]{1,5}$', length):
                length_1, length_2 = length.split('-')
                if int(length_1) not in range(0, 65536) or int(length_2) not in range(0, 65536):
                    print(f'Error: {length} is not a valid length range')
                    exit(1)
                if int(length_1) > int(length_2):
                    print(f'Error: {length} is not a valid length range')
                    exit(1)
            elif length.isnumeric():
                if int(length) not in range(0, 65536):
                    print(f'Error: {length} is not a valid length value')
                    exit(1)
    else:
        exit(2)

    exit(0)