spf2ip

raw JSON →
1.0.5 verified Fri May 01 auth: no python

A Python module to resolve IP addresses from an SPF (Sender Policy Framework) DNS record. Returns a set of IPv4 and IPv6 addresses for the given domain. Version 1.0.5, stable release.

pip install spf2ip
error ModuleNotFoundError: No module named 'spf2ip'
cause Library not installed
fix
Run: pip install spf2ip
error AttributeError: module 'spf2ip' has no attribute 'get_ip_addresses'
cause Incorrect import (e.g., 'import spf2ip' then calling spf2ip.get_ip_addresses)
fix
Use: from spf2ip import get_ip_addresses
error spf2ip.exceptions.DNSError: DNS resolution failed
cause Domain has no SPF record or network is down
fix
Check domain has valid SPF record and ensure DNS is reachable.
gotcha The function returns a set, not a list. May cause confusion if you expect ordered results.
fix Use sorted(ips) or list(ips) if order is needed.
gotcha DNS lookups can be slow or fail; ensure network connectivity or handle exceptions.
fix Wrap call in try-except for spf2ip.exceptions.DNSError or general Exception.
gotcha SPF records with includes/macros are resolved, but recursion depth is limited; very complex SPF records may return incomplete results.
fix Manually verify against authoritative SPF for large domains.

Retrieve all IP addresses authorized by the SPF record for a domain.

from spf2ip import get_ip_addresses

ips = get_ip_addresses('example.com')
print(ips)
# Output: {'192.0.2.1', '198.51.100.1', '2001:db8::1'}