【问题标题】:scapy timestamp measurement for outgoing packets传出数据包的scapy时间戳测量
【发布时间】:2017-09-18 09:40:42
【问题描述】:

有没有办法测量通过 scapy 发送的传出数据包的时间戳?如何以标准化值呈现这些时间戳,例如wireshark中的时间戳。

我可以通过

发送一个简单的数据包流
packet=IP(src="192.168.0.254", dst="192.168.0.2")/TCP(sport=35021, dport=35021)
pkt=sniff(filter="host 192.168.0.254")

当我从另一个终端嗅探时,

pkt=sniff(filter="host 192.168.0.254")
for p in pkt:
    print p[TCP].time

给我以下时间值

1505733059.335
1505733059.336
1505733059.336
1505733059.336
1505733059.337
1505733059.337
1505733059.338
1505733059.338
1505733059.338
1505733059.339

据我所知,这些是发送数据包时的值,对吧?如何将这些值更改为规范化的值,例如在 wireshark 中?

【问题讨论】:

  • 这是一个非常广泛和普遍的问题,就像你所说的那样。您是否搜索过任何教程?你写过代码吗?请表现出一些努力。
  • 添加了描述和代码。我希望现在你能有完整的想法。如果还需要回答这个问题,请告诉我。

标签: python python-2.7 timestamp scapy


【解决方案1】:

嗅探包的time 属性实际上表示接收包的时间,而不是发送时间。事实上,即使 Wireshark 与嗅探数据包相关联的时间也是它被接收到的时间,如 detailed in the official wiki

没有直接的方法来提取嗅探数据包的发送时间。可以尝试测量网络延迟并据此推断发送时间,但这种方法的准确性值得怀疑。另一种选择是在发送机器上提取发送时间并以某种方式将其传输到嗅探机器,如果正在使用可控制的自组织协议,则在带内或在带外,但这两种方法似乎都相当不雅,而且只有在发送机器可以被操纵的情况下才可行。


time 属性中存储的值等价于the time.time() function 的返回值,即自epoch 以来的时间(以秒为单位),即时间开始的点并且取决于平台。

这些值可以通过将它们传递给the time.gmtime() function 或在当地时间传递给the time.localtime() function 转换为更常见的时间格式(即年、月、日、小时等)。在这两种情况下都会返回一个struct_time object,从中可以将日历日期的组件作为属性访问。将返回的 struct_time 对象传递给 the time.asctime() function 会将其转换为人类可读的字符串格式,尽管通过 the time.strftime() function 可以更好地控制人类可读的输出。

Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import time
>>>
>>> timestamp = time.time()
>>> print(timestamp)
1505806452.8678658
>>>
>>> local_time = time.localtime(timestamp)
>>> print(local_time)
time.struct_time(tm_year=2017, tm_mon=9, tm_mday=19, tm_hour=10, tm_min=34, tm_sec=12, tm_wday=1, tm_yday=262, tm_isdst=1)
>>>
>>> human_time = time.asctime(local_time)
>>> print(human_time)
Tue Sep 19 10:34:12 2017
>>> 
>>> my_human_time = time.strftime('%A, %d/%m/%y, %I:%M:%S %p', local_time)
>>> print(my_human_time)
Tuesday, 19/09/17, 10:34:12 AM
>>> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多