传出数据包的 scapy 时间戳测量
scapy timestamp measurement for outgoing packets
有什么方法可以测量通过 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 中?
嗅探数据包的time
属性实际上表示接收数据包的时间,而不是发送时间。事实上,即使 Wireshark 与嗅探数据包相关联的时间也是它被接收的时间,如 detailed in the official wiki.
没有直接的方法来提取嗅探数据包的发送时间。可以尝试测量网络延迟并据此推断发送时间,但这种方法的准确性值得怀疑。另一种选择是在发送机器上提取发送时间并以某种方式将其传输到嗅探机器,如果正在使用可控的临时协议,则在带内或在带外,但两种方法看起来都相当不优雅并且是只有在发送机器可能被操纵的情况下才可行。
存储在 time
属性中的值等同于 the time.time()
function, which is the time in seconds since the epoch 的 return 值,即时间开始的时间点并且取决于平台。
这些值可以通过将它们传递给 the time.gmtime()
function or in local time by passing them to the time.localtime()
function. In both cases a struct_time
object is returned, from which the components of the calendar date may be accessed as attributes. Passing on the returned struct_time
object to the time.asctime()
function converts it to a human readable string format, though better control of the human readable output is possible via the time.strftime()
function.
转换为 UTC 中更常见的时间格式(即年、月、日、小时等)
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
>>>
有什么方法可以测量通过 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 中?
嗅探数据包的time
属性实际上表示接收数据包的时间,而不是发送时间。事实上,即使 Wireshark 与嗅探数据包相关联的时间也是它被接收的时间,如 detailed in the official wiki.
没有直接的方法来提取嗅探数据包的发送时间。可以尝试测量网络延迟并据此推断发送时间,但这种方法的准确性值得怀疑。另一种选择是在发送机器上提取发送时间并以某种方式将其传输到嗅探机器,如果正在使用可控的临时协议,则在带内或在带外,但两种方法看起来都相当不优雅并且是只有在发送机器可能被操纵的情况下才可行。
存储在 time
属性中的值等同于 the time.time()
function, which is the time in seconds since the epoch 的 return 值,即时间开始的时间点并且取决于平台。
这些值可以通过将它们传递给 the time.gmtime()
function or in local time by passing them to the time.localtime()
function. In both cases a struct_time
object is returned, from which the components of the calendar date may be accessed as attributes. Passing on the returned struct_time
object to the time.asctime()
function converts it to a human readable string format, though better control of the human readable output is possible via 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
>>>