在Scapy中指定每个数据包的时间戳?

gak*_*gak 4 python scapy

使用Scapy,当我创建数据包并将其写入pcap文件时,它会将数据包的时间戳设置为当前时间.

这是我目前的用法.1335494712.991895是我创建数据包的时间:

>>> a = Ether()/IP(src='1.1.1.1',dst='2.2.2.2')/TCP(sport=1337,dport=31337)
>>> wrpcap('single-tcp-packet.pcap', a)

# tcpdump -tt -r single-tcp-packet.pcap
reading from file single-tcp-packet.pcap, link-type EN10MB (Ethernet)
1335494712.991895 IP 1.1.1.1.menandmice-dns > arennes-651-1-107-2.w2-2.abo.wanadoo.fr.31337: Flags [S], seq 0, win 8192, length 0
Run Code Online (Sandbox Code Playgroud)

如何为每个数据包指定自己的时间戳?

我在文档中看到了用于设置TCP时间戳的时间戳,但它似乎没有对实际pcap时间戳产生影响.

gak*_*gak 6

啊! 找到了.

只是:

>>> a.time = 1234567890
>>> wrpcap('single-tcp-packet.pcap', a)

# tcpdump -tt -r single-tcp-packet.pcap
reading from file single-tcp-packet.pcap, link-type EN10MB (Ethernet)
1234567890.000000 IP 1.1.1.1.menandmice-dns > arennes-651-1-107-2.w2-2.abo.wanadoo.fr.31337: Flags [S], seq 0, win 8192, length 0
Run Code Online (Sandbox Code Playgroud)

  • Gerald,如果你想在scapy中看到那个时间戳的人类可读版本,我可以在datetime导入日期时间之后使用它打印datetime.fromtimestamp(pkt.time).strftime('%Y-%m- $ d%H :%M:%S').split('')[1] (2认同)