Recently I needed to fetch IP ranges from SPF records. After looking at different python/ruby/perl modules I came to the conclusion that a fancy module (sometimes with wonky dependencies) was overkill just to parse a simple SPF record. So I threw together a simple bash script that is mainly just fetching the SPF record with dig and grep:
1 |
dig txt "${fqdn}"|grep -oE 'v=spf[0-9] [^"]+'
|
It iterates through the options (it currently recognizes a, mx, ip4, ip6, include, and redirect), and then sorts the output by ipv4, then ipv6.
1
2
3
4
5
6
|
fetch_spf.sh ryanschulze.net
138.201.86.179
138.201.86.184
192.249.58.230
2a01:4f8:172:2270:1::102
2604:180::ef4b:4638
|
Download URL: fetch_spf.sh