大网数据广告活动
服务器运维问答

What is timestamp format of iptables recent proc-file?

· 52CE 我爱测

I want to understand meaning of records in /proc/net/xt_recent/ip_list file (which is created by recent extension of iptables ), e.g: src=127.0.0.1 ttl: 128 last_seen: 4298627364 oldest_pkt: 3 4298623492, 4298625777, 4298627364 A…

问题原文

原帖链接 · shau-kote · CC BY-SA 3.0

I want to understand meaning of records in /proc/net/xt_recent/ip_list file (which is created by recent extension of iptables), e.g:

src=127.0.0.1 ttl: 128 last_seen: 4298627364 oldest_pkt: 3 4298623492, 4298625777, 4298627364

All fields look pretty obvious and last_look look like timestamp. But it isn't timestamp in UNIX-time format. Being converted as UNIX-time is equal 03/21/2106 18:19:24. Evidently it isn't a "last seen" time.

How can I extract correct value from last_seen time?

Thank you.

UPDATE

Just to avoid misconception:

$ date 
Mon Jun 15 14:14:00 MSK 2015

已采纳解答

原帖链接 · Maxiko · CC BY-SA 4.0

This should works:

FILE=iplist #This is file name of recent module output. It may vary on your system (like iplist)
TICKS=$(grep CONFIG_HZ= /boot/config-$(uname -r)|awk -F= '{print $2}') # Get current ticks per sec

printit()
{
    Len=`echo $1|wc -c`
    Date=$DATE
    Dot="."
    Loop=`echo 50-$Len|bc`
    loop=0
    while [ $loop -le $Loop ]
    do
        loop=`echo $loop+1|bc`
        Dot=`echo $Dot.`
    done
    echo "$1$Dot$DATE"
}
cat $FILE|while read LINE
do
    IP=`echo $LINE|awk '{print $1}'|awk -F= {'print $2'}`
    DATE=$(date -d@$(date +'%s'-$(echo \($(cat /proc/timer_list|grep -m1 -E '^jiffies'|cut -d" " -f2)-$(awk '{print $5}' $FILE)\)/$TICKS|bc)|bc))
    printit $IP $DATE
done

And there is an output of your example:

127.0.0.1..........................................Пн. мая 18 14:24:40 OMST 2015

Timezone may differ from you regional settings

Also you can check https://stackoverflow.com/questions/2731463/converting-jiffies-to-milli-seconds

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-06-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。