I'm new to python i have set for Pcap files in a directory. i should read each file and extract the required data based on differnt variable for each file. i'm using pyshark for parsing pcap.
i have to take csv file column as an input for each filtering file
for example i have 4 files each in src- and dst- so first file i should be filtered by taking 10.272.726.227 only and for 2nd file 10.272.726.228 etc...
see below,
files = os.listdir('./Pcap')
csv_file=pd.read_csv('input.csv')
ip_src = csv_file.SRC_privateIp.tolist()
ip_dst = csv_file.DST_privateIp.tolist()
for file in files:
if file.startswith('src-'):
cap_src = pyshark.FileCapture(file, only_summaries = True)
for packet in cap_src:
line=str(packet)
formattedline = line.split(' ')
if formattedline[2] == ip_src and formattedline[3] == ip_dst:
print(formattedline)
if file.startswith('dst-'):
cap_src = pyshark.FileCapture(file, only_summaries = True)
for packet in cap_src:
line=str(packet)
formattedline = line.split(' ')
if formattedline[2] == ip_dst and formattedline[3] == ip_src :
print(formattedline)
I tried to open each file and do processing on each file separately but it is taking all files data in one string. I want each file to open one by one, do processing because each file has different conditions to filter out the necessary. The above code gives an error This event loop is already running. i dont know how to proceed further Can anybody help me out?
Thanks!