| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mail::MXplus; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25854
|
use 5.008; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
41
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
126
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# since there's only one thing to export, I export 'everything' |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
15
|
|
|
|
|
|
|
mxplus |
|
16
|
|
|
|
|
|
|
) ] ); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
21
|
|
|
|
|
|
|
mxplus |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# the code goes here |
|
31
|
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
1307
|
use Net::DNS; |
|
|
1
|
|
|
|
|
123197
|
|
|
|
1
|
|
|
|
|
638
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub mxplus { |
|
35
|
2
|
|
|
2
|
0
|
15
|
my ($domain, $ip) = @_; |
|
36
|
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
35
|
my $res = Net::DNS::Resolver->new; |
|
38
|
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
670
|
my @list; |
|
40
|
|
|
|
|
|
|
my @answer; |
|
41
|
0
|
|
|
|
|
0
|
my $rr; |
|
42
|
0
|
|
|
|
|
0
|
my $type; |
|
43
|
0
|
|
|
|
|
0
|
my $testip; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Perform a lookup, without the searchlist |
|
46
|
2
|
|
|
|
|
15
|
my $packet = $res->query($domain, 'MX'); |
|
47
|
|
|
|
|
|
|
# (returns undef if no MX records) |
|
48
|
|
|
|
|
|
|
|
|
49
|
2
|
50
|
|
|
|
11433
|
if (defined($packet)) { |
|
50
|
2
|
|
|
|
|
7
|
@list = (); |
|
51
|
2
|
|
|
|
|
8
|
@answer = $packet->answer; |
|
52
|
2
|
|
|
|
|
14
|
foreach $rr (@answer) { |
|
53
|
2
|
|
|
|
|
13
|
$type = $rr->type; |
|
54
|
2
|
50
|
|
|
|
28
|
if ($type eq 'MX') { |
|
55
|
2
|
|
|
|
|
9
|
push (@list, $rr->exchange); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
} else { |
|
59
|
0
|
|
|
|
|
0
|
@list = ($domain); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#truncate the IP to a dotted triplet for easier compare |
|
63
|
2
|
|
|
|
|
153
|
$testip = $ip; |
|
64
|
2
|
|
|
|
|
16
|
$testip =~ s/\.[0-9]+$/./; |
|
65
|
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
6
|
foreach (@list) { |
|
67
|
|
|
|
|
|
|
#lookup the A record. |
|
68
|
2
|
|
|
|
|
10
|
$packet = $res->query($_, 'A'); |
|
69
|
2
|
50
|
|
|
|
3347
|
if (defined($packet)) { |
|
70
|
2
|
|
|
|
|
9
|
@answer = $packet->answer; |
|
71
|
2
|
|
|
|
|
25
|
foreach $rr (@answer) { |
|
72
|
2
|
|
|
|
|
12
|
$type = $rr->type; |
|
73
|
2
|
50
|
|
|
|
23
|
if ($type eq 'A') { |
|
74
|
|
|
|
|
|
|
#compare it to the IP. |
|
75
|
2
|
100
|
|
|
|
9
|
if ($rr->address =~ /^$testip/) { |
|
76
|
1
|
|
|
|
|
71
|
return "pass"; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#if none of those were it, then check the rDNS |
|
84
|
1
|
50
|
|
|
|
48
|
if ($ip =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/) { |
|
85
|
1
|
|
|
|
|
10
|
my $rdns = "$4.$3.$2.$1.in-addr.arpa"; |
|
86
|
1
|
|
|
|
|
5
|
$packet = $res->query($rdns, 'PTR'); |
|
87
|
1
|
50
|
|
|
|
9581
|
if (defined($packet)) { |
|
88
|
0
|
|
|
|
|
0
|
@answer = $packet->answer; |
|
89
|
0
|
|
|
|
|
0
|
foreach $rr (@answer) { |
|
90
|
0
|
|
|
|
|
0
|
$type = $rr->type; |
|
91
|
0
|
0
|
|
|
|
0
|
if ($type eq 'PTR') { |
|
92
|
0
|
0
|
|
|
|
0
|
if ($rr->ptrdname =~ /$domain$/) { |
|
93
|
0
|
|
|
|
|
0
|
return "pass"; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
1
|
|
|
|
|
29
|
return "fail"; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
|
103
|
|
|
|
|
|
|
__END__ |