首先是抓包,使用scapy模块,
sniff()函数 在其中参数为本地文件路径时,操作为打开本地文件
若参数为BPF过滤规则和回调函数,则进行Sniff,回调函数用于对Sniff到的数据包进行处理
import os
from scapy.all import *
pkts=[]
count=0
pcapnum=0
filename=''
def test_dump_file(dump_file):
print "Testing the dump file..."
if os.path.exists(dump_file):
print "dump fie %s found." %dump_file
pkts=sniff(offline=dump_file)
count = 0
while (count<=2):
print "----Dumping pkt:%s----" %dump_file
print hexdump(pkts[count])
count +=1
else:
print "dump fie %s not found." %dump_file
def write_cap(x):
global pkts
global count
global pcapnum
global filename
pkts.append(x)
count +=1
if count ==3: <sp