如何使用Scapy提取原始TCP数据包 [英] How to extract Raw of TCP packet using Scapy
问题描述
我使用scapy模块的 sniff
函数。我的过滤器
和 prn
函数做得很好。但现在,我想提取 TCP数据包
的 Raw
,并使用十六进制或二进制格式处理它。 / p>
我该怎么做?
我试过 print packet [Raw]
但它似乎被转换为ASCII或类似的东西。我想保留它在十六进制或二进制。
您可以通过 STR(分组)
。要以可读格式将它们打印到屏幕上,您可以执行 print str(packet).encode(HEX)
。
I use the sniff
function of scapy module. My filter
and prn
function are doing a great job. But now, I would like to extract the Raw
of the TCP packet
and handle it using hexadecimal or binary format.
Here is the documentation of Packet Class in scapy.
How can I do that ?
I tried print packet[Raw]
but it seems to be converted as ASCII or something like that. I want to keep it in hexadecimal or binary.
You can get the raw bytes of the packet via str(packet)
. For printing them to the screen in a readable format you can execute print str(packet).encode("HEX")
.
这篇关于如何使用Scapy提取原始TCP数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!