#!/afs/athena/contrib/perl5/perl

use HTTP::Date;

while(<>){
    ($ip, $g, $g, $pdate, $tdate, @rest) = split;
    chop $tdate;
    $date = substr($pdate, 1);
    $date .= " $tdate";
    $hitwhen = str2time($date);

    push(@{$hits{$ip}}, $hitwhen);
    $slamcount{$ip}++;
    &slam_check($ip) if($slamcount{$ip} > 10);
}

sub slam_check {
    my $addr = shift;
    my $slam = 0;
    my $slamd, $slamtd;
    my @hitt = @{$hits{$addr}};
    $slamcount{$addr} = 0;
    for $i (0..($#hitt-1)){
	for $j (1..$#hitt){
	    next unless $j > $i;
	    $d = $j - $i;
	    next unless $d > 99;
	    if(($td = ($hitt[$j]-$hitt[$i])) < 1.2*$d){
		$slamd = $d;
		$slamtd = $td;
		$slam = 1;
	    }
	}
    }
    print("Slam from $addr: $slamd hits in $slamtd seconds\n") if $slam;
}
