| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::SPAMerLookup; |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE(<64>)cpan.orgE<gt> |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# $Id: SPAMerLookup.pm 376 2009-01-26 02:13:00Z lushe $ |
|
6
|
|
|
|
|
|
|
# |
|
7
|
1
|
|
|
1
|
|
594
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
36
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
9
|
1
|
|
|
1
|
|
875
|
use Net::DNS; |
|
|
1
|
|
|
|
|
102062
|
|
|
|
1
|
|
|
|
|
99
|
|
|
10
|
1
|
|
|
1
|
|
519
|
use Net::Domain::TldMozilla; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
1271
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @RBL_IP= qw/ |
|
15
|
|
|
|
|
|
|
niku.2ch.net |
|
16
|
|
|
|
|
|
|
all.rbl.jp |
|
17
|
|
|
|
|
|
|
list.dsbl.org |
|
18
|
|
|
|
|
|
|
/; |
|
19
|
|
|
|
|
|
|
our @RBL_URI= qw/ |
|
20
|
|
|
|
|
|
|
url.rbl.jp |
|
21
|
|
|
|
|
|
|
notop.rbl.jp |
|
22
|
|
|
|
|
|
|
all.rbl.jp |
|
23
|
|
|
|
|
|
|
/; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $TLDregex= do { |
|
26
|
|
|
|
|
|
|
my $tld= Net::Domain::TldMozilla->get_tld; |
|
27
|
|
|
|
|
|
|
join '|', map{quotemeta($_)}@$tld; |
|
28
|
|
|
|
|
|
|
}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub import { |
|
31
|
0
|
0
|
|
0
|
|
|
my $class= shift; $_[0] || return $class; |
|
|
0
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if (ref $_[0]) { |
|
33
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq 'HASH') { |
|
|
|
0
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
@RBL_URI= @{$_[0]->{URI}} if $_[0]->{URI}; |
|
|
0
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
@RBL_IP = @{$_[0]->{IP}} if $_[0]->{IP}; |
|
|
0
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} elsif (ref($_[0]) eq 'ARRAY') { |
|
37
|
0
|
|
|
|
|
|
@RBL_URI= @{$_[0]}; |
|
|
0
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} else { |
|
39
|
0
|
|
|
|
|
|
die __PACKAGE__.' - Argument of unsupported.'; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} else { |
|
42
|
0
|
|
|
|
|
|
@RBL_URI= @_; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
|
$class; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
sub new { |
|
47
|
0
|
|
|
0
|
|
|
bless []; ## no critic. |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
sub check_rbl { |
|
50
|
0
|
|
|
0
|
|
|
my $self= shift; |
|
51
|
0
|
|
0
|
|
|
|
my $args= shift || die q{I want 'host name' or 'IP address' or 'URL'.}; |
|
52
|
0
|
|
0
|
|
|
|
my $attr= shift || {}; |
|
53
|
0
|
|
0
|
|
|
|
my $timeout= $attr->{timeout} || $self->[0] || 10; |
|
54
|
0
|
|
|
|
|
|
$args=~s/\s+//; |
|
55
|
0
|
0
|
|
|
|
|
if ($args=~m{^(?:ftps?|https?|gopher|news|nntp|telnet|wais)\://([^/\:]+)}) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$args= $1; |
|
57
|
0
|
|
|
|
|
|
$args=~s/^[^\@]+\@//; |
|
58
|
0
|
|
|
|
|
|
$args=~s/^[^\:]+\://; |
|
59
|
0
|
0
|
|
|
|
|
$args=~m{^([^/\:]+)} || die q{Invalid argument.}; |
|
60
|
0
|
|
|
|
|
|
$args= $1; |
|
61
|
|
|
|
|
|
|
} elsif ($args=~m{^(?:mailto)\:(.+)}) { |
|
62
|
0
|
|
|
|
|
|
$args= $1; |
|
63
|
0
|
0
|
|
|
|
|
if ($args=~m{\@([^\@]+)$}) { $args= $1 } |
|
|
0
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} elsif ($args=~m{\@([^\@]+)$}) { |
|
65
|
0
|
|
|
|
|
|
$args= $1; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
|
|
|
|
|
my $dns= Net::DNS::Resolver->new; |
|
68
|
0
|
|
|
|
|
|
my $is_ip; |
|
69
|
|
|
|
|
|
|
my $check= $args=~m{^\d{1.3}\.\d{1.3}\.\d{1.3}\.\d{1.3}$} ? sub { |
|
70
|
0
|
|
|
0
|
|
|
$is_ip= 1; |
|
71
|
0
|
|
0
|
|
|
|
my $q= $dns->search("$args.$_[0]", 'PTR') || return 0; |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
0
|
|
|
|
|
|
address=> $args, |
|
74
|
0
|
|
|
|
|
|
result => [ map{$_->ptrdname}grep($_->type eq 'PTR', $q->answer) ], |
|
75
|
|
|
|
|
|
|
}; |
|
76
|
0
|
0
|
|
|
|
|
}: do { |
|
77
|
0
|
|
|
|
|
|
$is_ip= 0; |
|
78
|
0
|
|
|
|
|
|
my $domain; |
|
79
|
|
|
|
|
|
|
sub { |
|
80
|
0
|
|
0
|
0
|
|
|
my $q= $dns->search("$args.$_[0]", 'A') || do { |
|
81
|
|
|
|
|
|
|
$domain |
|
82
|
|
|
|
|
|
|
||= do { $args=~m{([^\.]+\.(?:$TLDregex))$} ? $1 : 'unmatch' }; |
|
83
|
|
|
|
|
|
|
return 0 if ($args eq $domain or $domain eq 'unmatch'); |
|
84
|
|
|
|
|
|
|
my $result= $dns->search("$domain.$_[0]", 'A') || return 0; |
|
85
|
|
|
|
|
|
|
$args= $domain; |
|
86
|
|
|
|
|
|
|
$result; |
|
87
|
|
|
|
|
|
|
}; |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
|
|
|
name => $args, |
|
90
|
0
|
|
|
|
|
|
result=> [ map{$_->address}grep($_->type eq 'A', $q->answer) ], |
|
91
|
|
|
|
|
|
|
}; |
|
92
|
0
|
|
|
|
|
|
}; |
|
93
|
|
|
|
|
|
|
}; |
|
94
|
0
|
|
|
|
|
|
eval { |
|
95
|
0
|
|
|
0
|
|
|
local $SIG{ALRM}= sub { die 'Timeout' }; |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
alarm $timeout; |
|
97
|
0
|
0
|
|
|
|
|
for ($is_ip ? @RBL_IP: @RBL_URI) { |
|
98
|
0
|
|
0
|
|
|
|
my $hit= $check->($_) || next; |
|
99
|
0
|
|
|
|
|
|
alarm 0; |
|
100
|
0
|
|
|
|
|
|
return { %$hit, RBL=> $_ }; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
0
|
|
|
|
|
|
alarm 0; |
|
103
|
|
|
|
|
|
|
}; |
|
104
|
0
|
0
|
|
|
|
|
if (my $error= $@) { $self->is_error($error) } |
|
|
0
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
0; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
sub is_error { |
|
108
|
0
|
|
|
0
|
|
|
my $self= shift; |
|
109
|
0
|
0
|
|
|
|
|
return $self->[1] unless @_; |
|
110
|
0
|
|
|
|
|
|
$self->[1]= shift; |
|
111
|
0
|
|
|
|
|
|
0; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
sub is_spamer { |
|
114
|
0
|
|
|
0
|
|
|
my $self= shift; |
|
115
|
0
|
0
|
|
|
|
|
for (@_) { if (my $target= $self->check_rbl($_)) { return $target } } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
0; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 NAME |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Net::SPAMerLookup - Perl module to judge SPAMer. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
use Net::SPAMerLookup { |
|
130
|
|
|
|
|
|
|
IP => [qw/ niku.2ch.net all.rbl.jp list.dsbl.org /], |
|
131
|
|
|
|
|
|
|
URI=> [qw/ url.rbl.jp notop.rbl.jp all.rbl.jp /], |
|
132
|
|
|
|
|
|
|
}; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $spam= Net::SPAMerLookup->new; |
|
135
|
|
|
|
|
|
|
if ($spam->check_rbl($TARGET)) { |
|
136
|
|
|
|
|
|
|
print "It is SPAMer."; |
|
137
|
|
|
|
|
|
|
} else { |
|
138
|
|
|
|
|
|
|
print "There is no problem."; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Whether SPAMer is contained in two or more objects is judged. |
|
142
|
|
|
|
|
|
|
if (my $spamer= $spam->is_spamer(@TARGET)) { |
|
143
|
|
|
|
|
|
|
print "It is SPAMer."; |
|
144
|
|
|
|
|
|
|
} else { |
|
145
|
|
|
|
|
|
|
print "There is no problem."; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
SPAMer is judged by using RBL. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Please set HTTP_PROXY of the environment variable if you use Proxy. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
see L<Net::Domain::TldMozilla>. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SETTING RBL USED |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
When passing it to the start option. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
use Net::SPAMerLookup qw/ all.rbl.jp ..... /; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
When doing by the import method. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
require Net::SPAMerLookup; |
|
165
|
|
|
|
|
|
|
Net::SPAMerLookup->import(qw/ all.rbl.jp ..... /); |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 METHODS |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 new |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Constructor. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $spam= Net::SPAMerLookup; |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 check_rbl ([ FQDN or IP_ADDR or URL ]) |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
'Host domain name', 'IP address', 'Mail address', and 'URL' can be passed to the argument. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
HASH including information is returned when closing in passed value RBL. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
0 is returned when not closing. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Following information enters for HASH that was able to be received. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=over 4 |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * RBL |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
RBL that returns the result enters. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * name or address |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
The value enters 'Address' at 'Name' and "IP address" when the object is "Host domain name" form. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * result |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Information returned from RBL enters by the ARRAY reference. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=back |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
if (my $result= $spam->check_rbl('samp-host-desuka.com')) { |
|
202
|
|
|
|
|
|
|
print <<END_INFO; |
|
203
|
|
|
|
|
|
|
It is SPAMer. |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
RBL-Server: $result->{RBL} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
@{[ $result->{name} ? qq{Name: $result->{name}}: qq{Address: $result->{address}} ]} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
@{[ join "\n", @{$result->{result}} ]} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
END_INFO |
|
212
|
|
|
|
|
|
|
} else { |
|
213
|
|
|
|
|
|
|
print "There is no problem."; |
|
214
|
|
|
|
|
|
|
...... |
|
215
|
|
|
|
|
|
|
... |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 is_error |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
error. |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 is_spamer ([TARGET_LIST]) |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
'check_rbl' is continuously done to two or more objects. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
And, HASH that 'check_rbl' returned is returned as it is if included. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
if (my $result= $spam->is_spamer(@TAGER_LIST)) { |
|
228
|
|
|
|
|
|
|
......... |
|
229
|
|
|
|
|
|
|
.... |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
L<Net::DNS>, |
|
234
|
|
|
|
|
|
|
L<Net::Domain::TldMozilla>, |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 AUTHOR |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lushe(E<64>)cpan.orgE<gt> |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Copyright (C) 2008 by Bee Flag, Corp. E<lt>http://egg.bomcity.com/E<gt>. |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
245
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
|
246
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
|
249
|
|
|
|
|
|
|
|