Skip to content

Instantly share code, notes, and snippets.

@frennkie
Last active Apr 23, 2021
Embed
What would you like to do?
#!/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