使用Scapy,我提取了以太网帧长度、IP有效载荷大小和标头长度,我想将这些信息写入csv文件以供进一步检查
from scapy.all import *
pcap = rdpcap('example.pcap')
out = open("out.csv", "wb")
for pkts in pcap:
ethernet_header = (len(pkts)) # IP payload size
ip_pload = (len(pkts.payload) - 20) # Ethernet frame length
ip_header = (len(pkts.payload)) # Total length IP header
print(ip_pload, len(pkts), ip_header)
out.write(ethernet_header, ip_pload, ip_header)
使用内置的csv。writer
,使用起来非常简单:
import csv
with open('out.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
for pkts in pcap:
ethernet_header = (len(pkts)) # IP payload size
ip_pload = (len(pkts.payload) - 20) # Ethernet frame length
ip_header = (len(pkts.payload)) # Total length IP header
writer.writerow([ethernet_header, ip_pload, ip_header])