mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-10 01:05:42 +00:00
feature: pcapConverter runs over all pcap in directory
This commit is contained in:
parent
f50e99c753
commit
4a8dbe2d4e
1 changed files with 45 additions and 29 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue