1#!/usr/local/bin/python3.8
2
3import re
4import sys
5
6def main():
7    if len(sys.argv) != 3:
8        print("Missing arguments: ./radv_check_va.py <bo_history> <64-bit VA>")
9        sys.exit(1)
10
11    bo_history = str(sys.argv[1])
12    va = int(sys.argv[2], 16)
13
14    va_found = False
15    with open(bo_history) as f:
16        for line in f:
17            p = re.compile('timestamp=(.*), VA=(.*)-(.*), destroyed=(.*), is_virtual=(.*)')
18            m = p.match(line)
19            if m == None:
20                continue
21
22            va_start = int(m.group(2), 16)
23            va_end = int(m.group(3), 16)
24
25            # Check if the given VA was ever valid and print info.
26            if va >= va_start and va < va_end:
27                print("VA found: %s" % line, end='')
28                va_found = True
29    if not va_found:
30        print("VA not found!")
31
32if __name__ == '__main__':
33    main()
34