Reputation: 1
I working in Google Colab. I have pcap file (Network packet traffic of IoT sensors) and I want to extract the features from these packets and save it as csv file to start train machine learning algorithms. I install tshark. but I'm still have this problem (TypeError: can only concatenate str (not "Ether") to str) the error in line
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")
how can I solve that? and if you have any way to extract features easier than this way, please provide me.
Upvotes: 0
Views: 35
Reputation: 82
From what I could figure out of your code you're trying to run the tshark
command using the infile
option to get ip.len
and ip_hdr_len
out of the input file.
However, scapy.all.rdpcap()
doesn't return a file but instead returns packets[Packet]
object type which is not suited for your purpose.
You can instead use xx.fields.values()
to get the src.ip
, dst.ip
, ip.length
of each packet in the pcap
file
Upvotes: 0