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

编程入门 行业动态 更新时间:2024-10-24 13:32:32
本文介绍了在 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从文件 single-tcp-packet.pcap 中读取,链接类型 EN10MB(以太网)1335494712.991895 IP 1.1.1.1.menandmice-dns >arenes-651-1-107-2.w2-2.abo.wanadoo.fr.31337: Flags [S], seq 0, win 8192, length 0

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

我已经看到文档中提到的用于设置 TCP 时间戳的时间戳,但它似乎与实际的 pcap 时间戳没有区别.

解决方案

啊!找到了.

简单地说:

>>>a.时间 = 1234567890>>>wrpcap('single-tcp-packet.pcap', a)# tcpdump -tt -r single-tcp-packet.pcap从文件 single-tcp-packet.pcap 中读取,链接类型 EN10MB(以太网)1234567890.000000 IP 1.1.1.1.menandmice-dns >arenes-651-1-107-2.w2-2.abo.wanadoo.fr.31337: Flags [S], seq 0, win 8192, length 0

With Scapy, when I create a packet and write it to a pcap file, it sets the timestamp of the packet to the current time.

This is my current usage. 1335494712.991895 being the time I created the packet:

>>> 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

How can I specify my own timestamp per packet?

I have seen timestamp mentioned in the docs for setting the TCP timestamp, but it doesn't seem to make a difference to the actual pcap timestamp.

解决方案

Ah! Found it.

Simply:

>>> 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

更多推荐

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

本文发布于:2023-10-27 22:52:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据包   中为   时间   Scapy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!