解析数据包时间

如上图所示,秒数为 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 datetime

time_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?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值