#!/usr/bin/perl -w use strict; my %domains; my @domain_array = qw(ebay.com paypal.com americanbank.com usbank.com americangreetings.com); my $log_domain; my $host_test; my $host_cmp; my $host; my @bad_domains; my $spf; my $dkim; for (@domain_array) { $domains{$_}{"counter"} = 0; $domains{$_}{"dkim0"} = 0; $domains{$_}{"dkim1"} = 0; $domains{$_}{"dkim2"} = 0; $domains{$_}{"dkim3"} = 0; $domains{$_}{"dkim4"} = 0; $domains{$_}{"spf0"} = 0; $domains{$_}{"spf1"} = 0; $domains{$_}{"spf2"} = 0; $domains{$_}{"spf3"} = 0; $domains{$_}{"spf4"} = 0; } open ($log_domain, "logdata") || die "$!"; while (<$log_domain>) { ($host) = $_ =~ /domain=([\w\.]+?)\s/;#find regex for domain ($spf)= $_ =~ /spf=([0-4])\s/; #find regex for spf1 ($dkim) = $_ = /dkim=([0-4])\s/; # find regex for dkim1 ###IP Regex - I'm assuming the regex for this is --($IP) = $_ =~ /ip=(([0-1]?[0-9]{1,2}\.)|(2[0-4][0-9]\.)|(25[0-5]\.)){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))\s/; $host_test = 0; foreach $host_cmp (keys %domains) #pull each key from domains hash { if ($host =~ $host_cmp) # if host equals domain in hash, incriment counter { $domains{$host}{"counter"}++; $domains{$host}{"spf$spf"}++; $domains{$host}{"dkim$dkim"}++; $host_test = 1; #Test to ensure domain is present } } if ($host_test == 0) #if domain is not in array { push (@bad_domains , $host); } } print "Domain,\"Domain Count\",Dkim0,Dkim1,Dkim2,Dkim3,Dkim4,Spf0,Spf1,Spf2,Spf3,Spf4\n"; foreach $host_cmp (keys %domains) { print "$host_cmp,"; print $domains{$host_cmp}{"counter"}.","; print $domains{$host_cmp}{"dkim0"}.","; print $domains{$host_cmp}{"dkim1"}.","; print $domains{$host_cmp}{"dkim2"}.","; print $domains{$host_cmp}{"dkim3"}.","; print $domains{$host_cmp}{"dkim4"}.","; print $domains{$host_cmp}{"spf0"}.","; print $domains{$host_cmp}{"spf1"}.","; print $domains{$host_cmp}{"spf2"}.","; print $domains{$host_cmp}{"spf3"}.","; print $domains{$host_cmp}{"spf4"}."\n"; } print "The total amount of domains that we don't care about is ".($#bad_domains+1)."\n"; close ($log_domain);