#! /usr/bin/perl
# load module
use DBI;
$mins=300;
$rate_limit=10;
$IP=$ARGV[0];
$current_time = `date +"%Y%m%d%H%M%S"`;
$previous_time = `date +"%Y%m%d%H%M%S" -d "$mins minutes ago"`;
# connect
my $dbh = DBI->connect("DBI:mysql:database=logger;host=localhost", "dbuser", "dbpassword", {'RaiseError' => 1});
# execute SELECT query
my $sth = $dbh->prepare("SELECT COUNT(*) FROM access WHERE IP='$IP' AND datetime >= '$previous_time' AND datetime < '$current
_time'");
$sth->execute();
$count = $sth->fetchrow_array();
$sth->finish();
$count =
"(Couldn't obtain count)" if !
defined($count);
# clean up
$dbh->disconnect();