-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathspftree.pl
More file actions
executable file
·82 lines (67 loc) · 1.71 KB
/
spftree.pl
File metadata and controls
executable file
·82 lines (67 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
use strict;
use warnings;
use Net::DNS;
use Net::IP;
use Data::Dumper qw(Dumper);
my $host = $ARGV[0];
my @responses;
my $ip = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
my $spaces = " ";
#my $ip = $ARGV[1];
my ($found,$hostrecord);
print "\nDomain: $host\n";
#print "Searching for IP: $ip\n\n";
sub findIPMatch {
my ($checkip, $range) = @_;
my $testip = new Net::IP($checkip) || die;
my $testrange = new Net::IP($range) || die;
if ($testip->overlaps($testrange) == $IP_A_IN_B_OVERLAP) {
print "They overlap A in B\n";
exit;
} elsif ($testip->overlaps($testrange) == $IP_B_IN_A_OVERLAP) {
print "They overlap B in A\n";
exit;
} else {
print "They don't overlap!\n";
exit;
}
}
sub findRecord {
my ($search, $count) = @_;
my $res = Net::DNS::Resolver->new;
my $reply = $res->query($search, "TXT");
my $spf;
my (@includes, @ips);
if ($reply) {
foreach my $rr ($reply->answer) {
next unless $rr->string =~ /(v=spf[\s\S]*[^)])/;
$spf = $1;
}
}
@ips = $spf =~ /(?:(?:ip[46]:)|(?:a:))(\S+)/smg;
#print "IPS: $_ " foreach @ips;
#print "\n";
#foreach my $myiprange (@ips) {
# findIPMatch($ip, $myiprange);
#}
if ($spf =~ /$ip/) {
$found = $spf;
$hostrecord = $search;
}
@includes = $spf =~ /include:(\S+)/smg;
if (!@includes) {
--$count;
$spaces = " " x $count;
}
print "$spaces-> $search\n";
print "$spaces-> $spf\n\n";
$spaces = " " x $count++;
foreach my $domain (@includes) {
findRecord($domain, $count);
}
--$count;
}
#findIPMatch("8.8.8.8","199.122.121.0/24");
findRecord($host, 1);
#print "Found IP\n----------------\n$hostrecord\n\t$found\n";