数据包时间"/>
解析数据包时间
如上图所示,秒数为 0x5f852c68 = 1602563176
如下所示,将秒级时间戳转为日期
import time
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1602563176)))
打印结果为 2020-10-13 12:26:16, 与wireshark中显示的时间一致。
剩下的微秒时间为 0x080a6f = 526959 微妙, 即0.526959s, 与wireshark显示的时间一致。
将毫秒时间戳转日期:
import time
import datetimetime_s = 1602563176
time_us = 526959
time_ms = time_s * 1000 + time_us / 1000.0
d = datetime.datetime.fromtimestamp(time_ms/1000)
# 精确到毫秒
str1 = d.strftime("%Y-%m-%d %H:%M:%S.%f")
print(str1)
结果为: 2020-10-13 12:26:16.526959 , 与wireshark显示的基本一致。
解析pcapng packet header 中的timestamp
timestamp 字节码如下:
ts_high = 0x163D72B7
ts_low = 0xE302F621
ts_us = (ts_high << 32) | ts_low
ts_ms = ts_us / 1000000.0
d = datetime.datetime.fromtimestamp(ts_ms/1000.0)
# 精确到毫秒
str1 = d.strftime("%Y-%m-%d %H:%M:%S.%f")
print("str1: " + str1)
结果为:str1: 2020-10-13 12:26:16.526968
这与header中的时间一致
参考:How Do I Calculate the Timestamp in UTC in an Enhanced Packet Block?
更多推荐
解析数据包时间
发布评论