def parse_range_ip_filter(string):
m = re.match(r"([(0-9abcdef]{1,16})(?:-([0-9abcdef]{1,16}))?$", string.replace("0x", "").lower())
if not m:
raise argparse.ArgumentTypeError("'" + string + "' is not a range of number.")
#print(m.group(1))
#print(m.group(2))
start = min(int(m.group(1).replace("0x", ""), 16), int(m.group(2).replace("0x", ""), 16))
end = max(int(m.group(1).replace("0x", ""), 16), int(m.group(2).replace("0x", ""), 16)) or start
if start > end:
raise argparse.ArgumentTypeError("Invalid range specified.")
return list([start, end])
评论列表
文章目录