summaryrefslogtreecommitdiff
path: root/lib/DAKKAR/Net/DNSBLLookup/Result.pm
blob: 1c57e8f98b2ab1d269cf0a3be8558bde27bd824f (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package DAKKAR::Net::DNSBLLookup::Result; 
 
# copied from Net::DNSBLLookup v0.03 
 
use DAKKAR::Net::DNSBLLookup;
 
use strict;
 
use constant DNSBLLOOKUP_RESULT_OPEN_PROXY => 1;
use constant DNSBLLOOKUP_RESULT_SPAM => 2;
use constant DNSBLLOOKUP_RESULT_UNKNOWN => 3;
use constant DNSBLLOOKUP_RESULT_DYNAMIC_IP => 4;
 
my %result_type = (
   DNSBLLOOKUP_OPEN_RELAY() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_DYNAMIC_IP() => DNSBLLOOKUP_RESULT_DYNAMIC_IP,
   DNSBLLOOKUP_CONFIRMED_SPAM() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_SMARTHOST() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_SPAMHOUSE() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_LISTSERVER() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_FORMMAIL() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_OPEN_PROXY() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
   DNSBLLOOKUP_OPEN_PROXY_HTTP() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
   DNSBLLOOKUP_OPEN_PROXY_SOCKS() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
   DNSBLLOOKUP_OPEN_PROXY_MISC() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
   DNSBLLOOKUP_HIJACKED() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_MULTI_OPEN_RELAY() => DNSBLLOOKUP_RESULT_SPAM,
   DNSBLLOOKUP_UNKNOWN() => DNSBLLOOKUP_RESULT_UNKNOWN,
   );
 
sub new {
  my ($class) = @_;
  my $self = bless {}, $class;
  $self->{results} = {};
  return $self;
}
 
sub add {
  my ($self$dnsbl$address) = @_;
  my $address_lookup = $Net::DNSBLLookup::dns_servers{$dnsbl};
  if (ref($address_lookupeq 'HASH') {
    push @{$self->{results}->{$dnsbl}}, $address_lookup->{$address};
  } elsif (ref($address_lookupeq 'CODE') {
    push @{$self->{results}->{$dnsbl}}, &$address_lookup($address);
  }    
}
 
sub add_dnsbl {
  my ($self$dnsbl) = @_;
  $self->{dnsbl_responded}->{$dnsbl} = 1;
}
 
sub num_proxies_responded {
  my ($self) = @_;
  return scalar(keys %{$self->{dnsbl_responded}});
}
 
sub breakdown {
  my ($self) = @_;
  my ($total_spam$total_proxy$total_dyn$total_unknown) = (0,0,0,0);
  return unless exists $self->{results};
  while (my ($dnsbl$v) = each %{$self->{results}}) {
    my ($is_spam$is_proxy$is_dyn$is_unknown) = (0,0,0,0);
    for my $retval (@$v) {
      my $result_type = $result_type{$retval};
      if ($result_type == DNSBLLOOKUP_RESULT_OPEN_PROXY) {
$is_proxy = 1;
      elsif ($result_type == DNSBLLOOKUP_RESULT_SPAM) {
$is_spam = 1;
      elsif ($result_type == DNSBLLOOKUP_RESULT_DYNAMIC_IP) {
$is_dyn = 1;
      elsif ($result_type == DNSBLLOOKUP_RESULT_UNKNOWN) {
$is_unknown = 1;
      }
    }
    $total_proxy += $is_proxy;
    $total_spam += $is_spam;
    $total_dyn += $is_dyn;
    unless ($is_proxy || $is_spam || $is_dyn) {
      $total_unknown += $is_unknown;
    }
  }
  return ($total_proxy$total_spam$total_dyn$total_unknown);
}
 
1;
 
__END__
 
=head1 NAME
 
Net::DNSBLLookup::Result - Analyze the DNS Blocklist lookup results
 
=head1 SYNOPSIS
 
  use Net::DNSBLLookup;
  my $dnsbl = Net::DNSBLLookup->new(timeout => 5);
  my $res = $dnsbl->lookup($ip_addr);
  my ($proxy, $spam, $unknown) = $res->breakdown;
  my $num_responded = $res->num_proxies_responded;
 
=head1 DESCRIPTION
 
The class represents objects returned by the lookup method of L<Net::DNSBLLookup>.
Currently it supports the breakdown between the number of Open Proxy and Spam hosts, as
well as the number of DNS Blocklist servers that actually responded.
 
=head1 METHODS
 
=over 4
 
=item breakdown
 
Returns the breakdown between the number of Open Proxy and Spam/Open Relay hosts.
It also returns the number of hits that are unknown - for example the DSBL blocklist
lumps all Open Proxy and Spam results into one code.
 
  ($proxy, $spam, $unknown) = $res->breakdown;
 
=item num_responded
 
Returns the total number of DNS Blocklists that responded to our queries within
C<timeout> seconds or less.
 
  $num_responded = $res->num_proxies_responded;
 
=back
 
=head1 SEE ALSO
 
L<Net::DNSBLLookup>
 
=head1 AUTHOR
 
TJ Mather, E<lt>tjmather@maxmind.comE<gt>
 
=head1 COPYRIGHT AND LICENSE
 
Copyright 2003 by MaxMind LLC
 
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. 
 
=cut