团队,我想从 wireshark pcap 文件中提取No_of_ARP_Request
, No_of_TCP_SYN
, Number_UDP_138
, NBNS
, MDNS
, IGMP
, ICMP data Src_MAC_Address
, Dest_MAC_Address
,Src_Port
等特征。
这是为了通知,我已经提取了特征并通过 DPKT 为 ARP 数据保存为 CSV。对于如何通过 DPKT 提取所有特征并保存为 CSV,任何人都可能有更好的建议或代码。谢谢你。Dest_Port
def arp_analys(filename):
with open("../data/" + filename + ".pcap", 'rb') as f:
pcap = dpkt.pcap.Reader(f)
requests = []
replies = []
for ts, buf in pcap:
eth = dpkt.ethernet.Ethernet(buf)
# If the packet is not arp
if eth.type != 2054:
continue
try:
arp = eth.arp
except Exception as e:
continue
packet_time = datetime.datetime.utcfromtimestamp(ts).strftime("%m/%d/%Y,%H:%M:%S")
src = dpkt.socket.inet_ntoa(arp.spa)
tgt = dpkt.socket.inet_ntoa(arp.tpa)
# Src and Dest MAC
from src.arpbasic import mac_addr
s_mac = mac_addr(eth.src)
d_mac = mac_addr(eth.dst)