feature: pcapConverter runs over all pcap in directory

This commit is contained in:
uhi22 2023-04-18 00:28:32 +02:00
parent f50e99c753
commit 4a8dbe2d4e

View file

@ -12,18 +12,20 @@
import pyshark import pyshark
import exiConnector import exiConnector
import os
inputFileName = "efcaec23.pcap"
cap = pyshark.FileCapture(inputFileName, display_filter="ipv6") def convertPcapToTxt(inputFileName):
fileOut = open(inputFileName + '.decoded.txt', 'w') cap = pyshark.FileCapture(inputFileName, display_filter="ipv6")
#print(cap) fileOut = open(inputFileName + '.decoded.txt', 'w')
#print(cap[0]) #print(cap)
#print(cap[1]) #print(cap[0])
#print(dir(cap[1])) #print(cap[1])
#print(cap[1].sniff_time) # readable time #print(dir(cap[1]))
#print(cap[1].sniff_timestamp) # epoch time #print(cap[1].sniff_time) # readable time
numberOfPackets=0 #print(cap[1].sniff_timestamp) # epoch time
for packet in cap: numberOfPackets=0
for packet in cap:
numberOfPackets+=1 numberOfPackets+=1
#print(packet) #print(packet)
if 'TCP' in packet: if 'TCP' in packet:
@ -41,5 +43,19 @@ for packet in cap:
print(decoded) print(decoded)
print(sHeader, file=fileOut) print(sHeader, file=fileOut)
print(decoded, file=fileOut) print(decoded, file=fileOut)
fileOut.close() fileOut.close()
# assign directory
directory = '../temp'
# iterate over files in
# that directory
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
# checking if it is a file
if os.path.isfile(f):
print(f)
if (f[-5:]==".pcap") or (f[-7:]==".pcapng"):
strFileNameWithPath = f
print("Will decode " + strFileNameWithPath)
convertPcapToTxt(strFileNameWithPath)