使用 scapy.sniff 获取 pcap 文件中的 'Ethernet Frame' 的问题

A Question with using scapy.sniff for get the 'Ethernet Frame' in pcap files

目的:从pcap文件中获取到达时间 语言:python3.7 工具:Scapy.sniff

最重要的是,我想在 .pcap 中获取到达时间数据,当我使用 wireshark 时,我在以太网帧中看到了数据,但是当我使用 #Scapy.sniff(offline='.pcap') ,我只得到了以太网、TCP、IP 和其他,那么我怎样才能得到这些数据呢? 非常感谢!

>>from scapy.all  import *
>>a = sniff(offline = '***.pcap')
>>a[0]

[out]:
<Ether  dst=*:*:*:*:*:* src=*:*:*:*:*:* type=** |<IP  version=4 ihl=5 tos=0x20 len=52 id=14144 flags=DF frag=0 ttl=109 proto=tcp chksum=0x5e3b src=*.*.*.* dst=*.*.*.* |<TCP  sport=gcsp dport=http seq=1619409885 ack=1905830025 dataofs=8 reserved=0 flags=A window=65535 chksum=0xfdb5 urgptr=0 options=[('NOP', None), ('NOP', None), ('SAck', (1905831477, 1905831485))] |>>>
[ ]:

来自 pcap 的数据包时间在 time 成员中可用:

print(a[0].time)

它被保存为浮点值(标准 python "timestamp" 格式)。为了以更容易理解的形式获取它,您可能需要使用 datetime 模块:

>>> from datetime import datetime
>>> dt = datetime.fromtimestamp(a[0].time)
>>> print(dt)
2018-11-12 03:03:00.259780

scapy 文档不是很好。使用交互式帮助工具可能非常有启发性。例如,在解释器中:

$ python
>>> from scapy.all import *
>>> a = sniff(offline='mypcap.pcap')
>>> help(a[0])

这将向您显示 a[0] 所表示的对象的所有方法和属性。在您的情况下,这是 class Ether(scapy.packet.Packet).

的一个实例