#!/usr/bin/perl use strict; use warnings; use POSIX; use LWP::Simple; use File::Copy; use Carp; my $ipdb = 'GeoIP.dat'; my $datadir = '/usr/share/GeoIP/'; my $fullpath = $datadir . $ipdb; my $url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz'; my $date = strftime '%Y%m%d', localtime; # Do we have an existing IP database? if ( -e $fullpath ) { print "Fetching " . $ipdb . " from " . $url . "\r\n"; if ( is_success( getstore( $url, $datadir . 'GeoIP.dat.gz' ) ) ) { move( $fullpath, $datadir . $ipdb . '.' . $date ) || croak "Can't move the old database aside\r\n"; system 'gzip', '-d', $datadir . 'GeoIP.dat.gz'; if ( $? ne 0 ) { croak "Could not uncompress database - exited $?\r\n"; } print "GeoIP database updated. Old copy is at " . $ipdb . "." . $date . "\r\n"; } else { croak "Fetch failed - try again later?\r\n"; } } else { croak "You don't appear to have a valid GeoIP database installed..\r\n"; }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
AUTHORS | File | 35 B | 0644 |
|
COPYING | File | 25.98 KB | 0644 |
|
ChangeLog | File | 32.8 KB | 0644 |
|
LICENSE.txt | File | 1.87 KB | 0644 |
|
README | File | 7.76 KB | 0644 |
|
TODO | File | 2.5 KB | 0644 |
|
fetch-geoipdata-city.pl | File | 1.04 KB | 0644 |
|
fetch-geoipdata.pl | File | 1.04 KB | 0644 |
|