scapy模块分析数据包
scapy是python写的一个功能强大的交互式数据包处理程序,可用来发送、嗅探、解析和伪造网络数据包,常常被用到网络攻击和测试中。----(网上抄的介绍...)
https://scapy.readthedocs.io/en/latest/usage.html#starting-scapy 官方文档
pip install scapy 安装scapy就好了
from scapy.all import *
a = rdpcap("data.pcap") #读取本地数据包
>>> a
<data.pcap: TCP:7068 UDP:326 ICMP:2120 Other:107>
a.summary() #displays a list of summaries of each packet,这个太多了
Command | Effect |
---|---|
summary() | displays a list of summaries of each packet |
nsummary() | same as previous, with the packet number |
conversations() | displays a graph of conversations |
show() | displays the preferred representation (usually nsummary()) |
filter() | returns a packet list filtered with a lambda function |
hexdump() | returns a hexdump of all packets |
hexraw() | returns a hexdump of the Raw layer of all packets |
padding() | returns a hexdump of packets with padding |
nzpadding() | returns a hexdump of packets with non-zero padding |
plot() | plots a lambda function applied to the packet list |
make table() | displays a table according to a lambda function |
看一点效果图
类似于 python 中的 list 类型, 可以使用下标访问,长度可以使用 len 计算 ,但数据不是list也不是string,如果要进行str操作需要,str(dpkg)
如果安装了pyx模块,则可以将分析结果转换为图片格式(pyx只支持python3)
dpkt.psdump() | draws a PostScript diagram with explained dissection |
---|---|
dpkt.pdfdump() | draws a PDF with explained dissection |