Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created January 21, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtetsuji/ee4a2f33ee34390c4af183df1e684efa to your computer and use it in GitHub Desktop.
Save xtetsuji/ee4a2f33ee34390c4af183df1e684efa to your computer and use it in GitHub Desktop.
count given domain "include" consider recursive "include"
#!/usr/bin/env perl
use strict;
use warnings;
my $check_mail_domain = shift;
if ( !$check_mail_domain || $check_mail_domain =~ / / ) {
die "1st argument is required as mail domain\n";
}
my $total_count = 0; # TODO: グローバル変数よくない
spf_include_hosts_recursive($check_mail_domain);
print "total=$total_count\n";
sub spf {
my $host = shift;
my $output = qx{host -t txt $host};
return join " ", $output =~ /v=spf1 +(.*)/g;
}
sub spf_include_hosts {
my $host = shift;
my @hosts = spf($host) =~ /include: *(\S+)/g;
return @hosts;
}
sub spf_include_hosts_recursive {
my $host = shift;
my @include_hosts = spf_include_hosts($host);
my $count_include_hosts = scalar @include_hosts;
$total_count += $count_include_hosts;
printf "%s: [%d] %s\n",
$host,
$count_include_hosts,
join(", ", @include_hosts);
sleep 2;
for my $include_host (@include_hosts) {
spf_include_hosts_recursive($include_host);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment