Add script for generating martians table from IANA IP IPv[46] special registry
This commit is contained in:
parent
a7c8d5e369
commit
495af218be
3 changed files with 86 additions and 0 deletions
38
utils/openbsd/pf-martians/iana-ip-special-registry-parser.py
Normal file
38
utils/openbsd/pf-martians/iana-ip-special-registry-parser.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
import csv
|
||||
import re
|
||||
import sys
|
||||
|
||||
REGEX_FOOTNOTES = re.compile(r" \[\d+\]")
|
||||
REGEX_WHITESPACES = re.compile(r"\s+")
|
||||
|
||||
def parse_iana_csv(csvfile):
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
fmt = ""
|
||||
reachable = row["Globally Reachable"]
|
||||
if reachable == "":
|
||||
continue
|
||||
if "False" in reachable:
|
||||
fmt = "{}"
|
||||
elif "True" in reachable:
|
||||
fmt = "!{}"
|
||||
elif "N/A" in reachable:
|
||||
fmt = "#{}"
|
||||
else:
|
||||
fmt = "#[" + reachable + "]: {}"
|
||||
blocks = row["Address Block"]
|
||||
blocks = REGEX_FOOTNOTES.sub("", blocks)
|
||||
blocks = REGEX_WHITESPACES.sub("", blocks)
|
||||
for block in blocks.split(","):
|
||||
print(fmt.format(block))
|
||||
|
||||
if __name__ == "__main__":
|
||||
def usage():
|
||||
print("Usage: {}".format(sys.argv[1]), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) != 1:
|
||||
usage()
|
||||
|
||||
parse_iana_csv(sys.stdin)
|
||||
Loading…
Add table
Add a link
Reference in a new issue