【问题标题】:Calculate the time delay between send and received packets using iperf3 and tcpdump?使用 iperf3 和 tcpdump 计算发送和接收数据包之间的时间延迟?
【发布时间】:2020-01-27 14:18:59
【问题描述】:

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

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

我也使用过日期时间库,但没有得到结果。

【问题讨论】:

    标签: python numpy-ndarray tcpdump tshark iperf3


    【解决方案1】:

    检查以下几行是否可以帮助您

    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)
    

    【讨论】:

    • 我希望时间格式为 2020 年 1 月 27 日 13:22:12.683438000 CET,小数点后有 9 位,以秒为单位。我该怎么做?
    • @Nehal ,你的问题是关于得到差异,希望我的代码回答它,对于不同的,差异不能来自区域名称,它总是在天,分钟,秒,年等,在格式化以下链接可以帮助...pytz.sourceforge.netdocs.python.org/3/library/datetime.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    相关资源
    最近更新 更多