使用iperf3和tcpdump计算发送和接收数据包之间的时间延迟?

2024-05-18 13:57:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经编写了一个bash代码来运行iperf3并捕获数据包。然后我使用tshark从.pcap文件中提取了帧时间。时间格式如下2020年1月27日13:22:12.683438000 CET.

现在我想计算发送和接收数据包之间的时间差,但我不知道如何减去这种格式的时间。 我应该使用哪种变量类型才能执行减法

我也使用了datetime库,但没有得到结果


Tags: 文件代码bash类型datetime格式时间pcap
1条回答
网友
1楼 · 发布于 2024-05-18 13:57:20

检查下面的行是否可以帮助您

from datetime import datetime
from pytz import timezone

CET = timezone('CET')

send_time = datetime.strptime('11:18:57.925 Wed Jan 5 2019', '%H:%M:%S.%f %a %b %d %Y')
print(send_time.astimezone(CET))
difference_from_now = send_time.astimezone(CET) - datetime.now().astimezone(CET)
print(difference_from_now)

received_time = datetime.strptime('08:18:57.925 Mon Jan 20 2020', '%H:%M:%S.%f %a %b %d %Y')
print(received_time.astimezone(CET))

difference_send_received = send_time.astimezone(CET) - received_time.astimezone(CET)

print(difference_send_received)

相关问题 更多 >

    热门问题