$res=mysql_query("select id from events order by id desc limit 1",$db);
$tmp=mysql_fetch_assoc($res);
#var_dump($tmp["id"]);
printf("WARN: no lastfile found, starting from now\n");
file_put_contents($lastfile,$tmp["id"]);
}else{
$res=mysql_query("select id from events order by id desc limit 1",$db);
$tmp=mysql_fetch_assoc($res);
$head=$tmp["id"];
$q="select max(detected) as max_detected, hostname, service, type, source, sum(attack_scale) as sum_attack_scale from events where id>$last AND id<=$head AND inet_aton(source) BETWEEN ".$mynet['first']." AND ".$mynet['last']." group by hostname, service,type,source;";