#!/usr/bin/perl
#
# usage: ipt_recent_analysis.pl <ip>

use strict;
use warnings;

my $f;

die "usage: ipt_recent_analysis.pl <ip>" unless @ARGV==1;

open $f, "</proc/uptime" or die $!;
$_ = <$f>;
close $f or die $!;
die "unable to parse uptime $_" unless /^([0-9]+\.[0-9]+)/;
my $boottime = time() - $1;

open $f, "</proc/net/ipt_recent/DEFAULT" or die $!;
my @hosts = <$f>;
close $f or die $!;

my $hostre = quotemeta($ARGV[0]);

foreach $_ (grep /$hostre/, @hosts) {
    chomp;
    next unless /last_pkts: (.*)$/;
    my @pkts = split /,\s*/,$1;
    foreach my $pkt (@pkts) {
	my $time = $boottime + ($pkt/1000);
	print scalar localtime($time),"\n";
    }
}

