解析数据包时间

编程入门 行业动态 更新时间:2024-10-18 21:16:19

解析<a href=https://www.elefans.com/category/jswz/34/1770940.html style=数据包时间"/>

解析数据包时间

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

更多推荐

解析数据包时间

本文发布于:2024-03-23 23:43:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1744235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据包   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!