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 exiConnector
import os
inputFileName = "efcaec23.pcap"
cap = pyshark.FileCapture(inputFileName, display_filter="ipv6")
fileOut = open(inputFileName + '.decoded.txt', 'w')
#print(cap)
#print(cap[0])
#print(cap[1])
#print(dir(cap[1]))
#print(cap[1].sniff_time) # readable time
#print(cap[1].sniff_timestamp) # epoch time
numberOfPackets=0
for packet in cap:
def convertPcapToTxt(inputFileName):
cap = pyshark.FileCapture(inputFileName, display_filter="ipv6")
fileOut = open(inputFileName + '.decoded.txt', 'w')
#print(cap)
#print(cap[0])
#print(cap[1])
#print(dir(cap[1]))
#print(cap[1].sniff_time) # readable time
#print(cap[1].sniff_timestamp) # epoch time
numberOfPackets=0
for packet in cap:
numberOfPackets+=1
#print(packet)
if 'TCP' in packet:
@ -41,5 +43,19 @@ for packet in cap:
print(decoded)
print(sHeader, 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)