commit 2df23367f35c571d640b92c4c16082c056065df1
parent 7bc9f56e4446e3906886964cf83bfd8ea061bba7
Author: sin <sin@2f30.org>
Date: Fri, 21 Apr 2017 11:22:13 +0100
Add fetch-spf script
Diffstat:
A | fetch-spf | | | 44 | ++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 44 insertions(+), 0 deletions(-)
diff --git a/fetch-spf b/fetch-spf
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+#
+# Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+$domain = shift @ARGV or die "usage: $0 domain";
+
+sub parsespf
+{
+ my $domain = shift;
+ my @foo = `nslookup -q=TXT $domain`;
+ my @results = ();
+
+ foreach (@foo) {
+ next if not /$domain\ttext/;
+ next if not s/$domain\ttext = "v=spf1([^"]+)"/$1/;
+
+ @results = split /\s+/;
+ foreach (@results) {
+ next if /.all/;
+ if (s/^ip[46]://) {
+ print "$_\n";
+ } elsif (s/^(redirect|include)[:=]//) {
+ print "\n#$_\n";
+ parsespf($_);
+ }
+ }
+ }
+}
+
+parsespf($domain);
+
+0;