File: geoip

package info (click to toggle)
qpsmtpd 0.84-9
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,376 kB
  • sloc: perl: 8,012; sh: 382; makefile: 61
file content (29 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (4)
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
# -*- perl -*-

=pod

This plugin uses MaxMind's GeoIP service and the Geo::IP perl module to
do a lookup on incoming connections and record the country of origin.

Thats all it does.

It logs the country to the connection notes 'geoip_country'.  Another
plugin can use that value to do things to the connection, like reject,
or greylist.

=cut

use Geo::IP;

sub hook_connect {
  my ($self) = @_;

  my $geoip = Geo::IP->new(GEOIP_STANDARD);
  my $country = 
    $geoip->country_code_by_addr( $self->qp->connection->remote_ip );

  $self->qp->connection->notes('geoip_country', $country);
  $self->log(LOGNOTICE, "GeoIP Country: $country");

  return DECLINED;
}