Reputation: 145
There are some wireshark .cap files. I need to split all these into 1 second time interval. I was able to split .cap files using below editcap command. Editcap -i time inputfile.cap outputfileprefix
Figure 1:Split files-output But as there are many files I want to split; I have to use this command separately for each file name one by one. This takes time. Therefore, I thought of writing a code that will check for all the .cap files in a given folder and will split all the files.
For example, when I give the path as ‘/root/Desktop/Testcap/’ the program should split all the .cap within the subfolders (likepost, shortcomment) as well. The output (split files) should get the name of the input file as shown in Figure1. This is what I wrote. import os path = '/root/Desktop/Testcap' for dir_name, sub_dirs, files in os.walk(path): for filename in files: if filename.endswith('.cap'): os.system('editcap -i 1 filename .....') How to complete from the bolded part ? Thanks
Upvotes: 1
Views: 139
Reputation: 46
You could do it in python, but find and xargs are good tools to learn and use:
find /root/Desktop/Testcap -name ‘*.cap’ -print0 | xargs -0 -n1 -I % editcap -i % %
The print0 and -0 are to handle spaces in filenames.
Or, if you want to do it in python:
#!/usr/bin/env python
import os
startdir='.'
suffix='.cap'
for root, dirs, files in os.walk(startdir):
for name in files:
if name.endswith(suffix):
filename=os.path.join(root,name)
cmd = 'editcap -i 1 "{}" "{}"'.format(filename,filename)
print(cmd)
os.system(cmd)
Upvotes: 1