将UDP数据包从x秒中保存在PCAP文件中
我正在尝试通过以太网连接从传感器到PC收到的UDP数据包。我想以PCAP文件的形式保存UDP数据。
到目前为止,我已经编写了以下代码来保存1个数据包。我运行了代码,然后使用Wireshark打开了保存的PCAP文件,并将其与Raw Wireshark数据的输出进行了比较。数据包1的0000-0010线相同,但0020线不同。 test.pcap仅捕获42个字节,而Wireshark数据包1的字节捕获了1236个字节。
如果我错了,请纠正我,但我认为这是由于我的代码没有给出足够的时间从数据包中收集所有数据。 我希望在下面修改我的代码时获得帮助,以便在时间间隔中节省PCAP文件。例如,PCAP文件将每5秒保存一次。
from scapy.all import wrpcap, Ether, IP, UDP
pkts = [Ether(src=" ", dst=" ") / IP(src=" ", dst=" ") / UDP(src=" ", dst=" ")]
wrpcap('test.pcap', [pkts])
I am trying to save UDP data packets which I receive from a sensor to my PC through ethernet connection. I want to save the UDP data in the form of a pcap file.
So far I have written the following code to save 1 packet of data. I ran my code then opened up the saved pcap file using wireshark and compared it to the output from the raw wireshark data. Lines 0000 - 0010 from packet 1 are the same but line 0020 is different. test.pcap only has 42 bytes captured whereas from wireshark packet 1 has 1236 bytes captured.
Correct me if I am wrong but I think this is due to my code not giving enough time to collect all the data from the packet. I was hoping to get help in modifying my code below so that it saves the pcap file in time intervals. For example a pcap file will be saved every 5 seconds.
from scapy.all import wrpcap, Ether, IP, UDP
pkts = [Ether(src=" ", dst=" ") / IP(src=" ", dst=" ") / UDP(src=" ", dst=" ")]
wrpcap('test.pcap', [pkts])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试此代码,让我知道您是否仍然得到较少的数据包:
Try this code, let me know if you are still getting less packets: