creating a pcap file using python

和自甴很熟 提交于 2019-11-28 07:11:52

问题


I'm trying to create a very simple PCAP file (1 UDP message).
Tried using dpkt (pcap.Writer), no luck, and the documentation is scarce.
Can anyone post a working example?
(or any other alternative - I'm not bound to dpkt)


回答1:


You may use Scapy.

https://scapy.readthedocs.io/en/latest/installation.html

If using Python 3:

pip3 install scapy

Then in Python:

from scapy.all import wrpcap, Ether, IP, UDP
packet = Ether() / IP(dst="1.2.3.4") / UDP(dport=123)
wrpcap('foo.pcap', [packet])



回答2:


construct's cap shows how to use construct for this. Construct also has a rudimentary ip stack example. The nice thing about Construct is that it is symmetrical, i.e. you can put data into it, convert it to a set of Python objects and you can then dump out the objects to create the original data blob again.




回答3:


you need to write the packet into a libpcap format

Global Header + Packet Header + Packet Data + Packet Header + Packet Data this link should help you

http://www.codeproject.com/Tips/612847/Generate-a-quick-and-easy-custom-pcap-file-using-P



来源:https://stackoverflow.com/questions/10868698/creating-a-pcap-file-using-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!