基本信息
源码名称:python抓取数据包提取五元组
源码大小:2.06KB
文件格式:.py
开发语言:Python
更新时间:2020-12-21
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

分析pcap包,从中提取出源地址 目的地址 和数据包的长度,目的端口,源端口,以及数据包内容

要准备好pcap数据包


for p in packets: try:
     list_dic=[]
     dic =  {}
     dic["Protocol"] = p[1].proto print(p[1].proto)
     dic["Destination"] = p[1].dst
     dic["Source"] = p[1].src
     ipto=str(p[1].dst) '--' str(p[1].src) if ipto not in ip_to:
        ip_to.append(ipto)
     dic["Sport"] = p[2].sport
     dic["Dport"]=p[2].dport
     GMTtime = string_data[i:i 4]
     lens = string_data[i 12:i 16]
     packet_GMTtime = struct.unpack('I', GMTtime)[0]
     packet_GMTtime = time_trans(packet_GMTtime)
     dic["time"]=repr(packet_GMTtime)
     packet_len = struct.unpack('I', lens)[0]
     packet_data = (string_data[i 16:i 16  packet_len])
     dic["data"]=repr(packet_data)
     i = i   packet_len 16  if ipto not in dic_all:
        dic_all[ipto]=list_dic
     dic_all[ipto].append(dic)