Last active
April 23, 2021 21:04
-
-
Save frennkie/39f71f68bf420cde10d73810a36a7abb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import ipaddress | |
from SPF2IP import SPF2IP | |
ignore_list = set({'127.0.0.1/32'}) | |
ignore_list.update({ # Microsoft O365 | |
'40.92.0.0/15', | |
'40.107.0.0/16', | |
'52.100.0.0/14', | |
'104.47.0.0/17' | |
}) | |
add_list = { | |
'127.0.0.2/32' | |
} | |
result = set() | |
for item in add_list: | |
result.add(item) | |
with open('domains.csv', 'r') as f: | |
lines = f.read().splitlines() | |
for line in lines: | |
try: | |
lookup = SPF2IP(line) | |
for r in lookup.IPArray('4'): | |
if r not in ignore_list: | |
result.add(r) | |
# TODO(frennkie) this is pretty "broad" | |
except Exception as e: | |
print(f"[WARN] {line}: {e}") | |
total = 0 | |
for item in result: | |
ia = ipaddress.IPv4Network(item) | |
total += ia.num_addresses | |
print("[INFO] ===") | |
print(f"[INFO] Total number of Ranges: {len(result)}") | |
print(f"[INFO] Total number of IPs: {total}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment