scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

fetch-spf (1267B)


      1 #!/usr/bin/perl
      2 #
      3 # Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
      4 #
      5 # Permission to use, copy, modify, and distribute this software for any
      6 # purpose with or without fee is hereby granted, provided that the above
      7 # copyright notice and this permission notice appear in all copies.
      8 #
      9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16 
     17 $domain = shift @ARGV or die "usage: $0 domain";
     18 
     19 sub parsespf
     20 {
     21 	my $domain = shift;
     22 	my @foo = `nslookup -q=TXT $domain`;
     23 	my @results = ();
     24 
     25 	foreach (@foo) {
     26 		next if not /$domain\ttext/;
     27 		next if not s/$domain\ttext = "v=spf1([^"]+)"/$1/;
     28 
     29 		@results = split /\s+/;
     30 		foreach (@results) {
     31 			next if /.all/;
     32 			if (s/^ip[46]://) {
     33 				print "$_\n";
     34 			} elsif (s/^(redirect|include)[:=]//) {
     35 				print "\n#$_\n";
     36 				parsespf($_);
     37 			}
     38 		} 
     39 	} 
     40 }
     41 
     42 parsespf($domain);
     43 
     44 0;