TypeError: can only concatenate str (not "Ether") to str

问题描述 投票:0回答:1

我在 Google Colab 工作。 我有 pcap 文件(物联网传感器的网络数据包流量),我想从这些数据包中提取特征并将其保存为 csv 文件以开始训练机器学习算法。 我安装了 tshark。但我仍然有这个问题(TypeError: can only concatenate str (not "Ether") to str) 行中的错误

  tsharkcommand = ("tshark -r" + xx +"-T fields -e ip.len -e ip_hdr_len")
import glob 
import os 

filey = open("try.csv",'a')
filey.writelines("Lable,IPlength,DestIP")
packets = rdpcap("bruteforce.pcapng")

for xx in packets:
  all = str (os.popen(tsharkcommand).read())
  all = all.splitlines()

  for features in all:
      filey.writelines("Lable"+ "," + features + "\n")

我该如何解决? 如果您有任何比这种方式更容易提取特征的方法,请提供给我。

python csv feature-extraction pcap tshark
1个回答
0
投票

根据我从您的代码中得出的内容,您正在尝试使用

tshark
选项运行
infile
命令以从输入文件中获取
ip.len
ip_hdr_len

但是,

scapy.all.rdpcap()
不返回文件,而是返回不适合您目的的
packets[Packet]
对象类型。

您可以改为使用

xx.fields.values()
来获取
src.ip
文件中每个数据包的
dst.ip
ip.length
pcap

© www.soinside.com 2019 - 2024. All rights reserved.