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