aboutsummaryrefslogtreecommitdiffstats
path: root/tools/indexcap.py
diff options
context:
space:
mode:
authorKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>2009-09-26 03:48:04 +0000
committerKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>2009-09-26 03:48:04 +0000
commit2f2dc6d571e2d273a9222aab23f42a366b45d55f (patch)
tree354e7460c803dfdc2112ccbe3136366d55ebffd3 /tools/indexcap.py
parent7be78a2d55ae1aacf0c3e11325e14dd54770cb0e (diff)
Add option to dump all files containing a protocol (possibly a comma delimited list of protocols)
svn path=/trunk/; revision=30160
Diffstat (limited to 'tools/indexcap.py')
-rwxr-xr-xtools/indexcap.py52
1 files changed, 38 insertions, 14 deletions
diff --git a/tools/indexcap.py b/tools/indexcap.py
index b09c7180e8..2a6070a268 100755
--- a/tools/indexcap.py
+++ b/tools/indexcap.py
@@ -53,7 +53,7 @@ def process_capture_file(tshark, file):
except KeyboardInterrupt:
return None
-def list_proto(cap_hash):
+def list_all_proto(cap_hash):
proto_hash = {}
for files_hash in cap_hash.itervalues():
for proto,count in files_hash.iteritems():
@@ -61,14 +61,27 @@ def list_proto(cap_hash):
print proto_hash
-def list_files(cap_hash):
+def list_all_files(cap_hash):
files = cap_hash.keys()
files.sort()
print files
+def list_all_proto_files(cap_hash, proto_comma_delit):
+ protos = [ x.strip() for x in proto_comma_delit.split(',') ]
+ files = []
+ for (file, files_hash) in cap_hash.iteritems():
+ for proto in files_hash.iterkeys():
+ if proto in protos:
+ files.append(file)
+ break
+
+ print files
+
def index_file_action(options):
- return options.list_proto or options.list_files
+ return options.list_all_proto or \
+ options.list_all_files or \
+ options.list_all_proto_files
def find_capture_files(paths, cap_hash):
cap_files = []
@@ -83,12 +96,19 @@ def find_capture_files(paths, cap_hash):
def main():
parser = OptionParser(usage="usage: %prog [options] index_file [file_1|dir_1 [.. file_n|dir_n]]")
- parser.add_option("-n", "--no-append", dest="append", default=True, action="store_false", help="Do not append to existing cache file")
- parser.add_option("-m", "--max-files", dest="max_files", default=sys.maxint, type="int", help="Max number of files to process")
- parser.add_option("-b", "--binary-dir", dest="bin_dir", default=os.getcwd(), help="Directory containing tshark executable")
- parser.add_option("-j", dest="num_procs", default=1, type=int, help="Max number of processes to spawn")
- parser.add_option("-l", "--list-proto", dest="list_proto", default=False, action="store_true", help="List all protocols in index file")
- parser.add_option("-f", "--list-files", dest="list_files", default=False, action="store_true", help="List all files in index file")
+ parser.add_option("-m", "--max-files", dest="max_files", default=sys.maxint, type="int",
+ help="Max number of files to process")
+ parser.add_option("-b", "--binary-dir", dest="bin_dir", default=os.getcwd(),
+ help="Directory containing tshark executable")
+ parser.add_option("-j", dest="num_procs", default=1, type=int,
+ help="Max number of processes to spawn")
+ parser.add_option("", "--list-all-proto", dest="list_all_proto", default=False, action="store_true",
+ help="List all protocols in index file")
+ parser.add_option("", "--list-all-files", dest="list_all_files", default=False, action="store_true",
+ help="List all files in index file")
+ parser.add_option("", "--list-all-proto-files", dest="list_all_proto_files", default=False,
+ metavar="PROTO_1[, .. PROTO_N]",
+ help="List all files in index file containing the given protocol")
(options, args) = parser.parse_args()
@@ -99,6 +119,7 @@ def main():
parser.error("one capture file/directory must be specified")
index_file_name = args.pop(0)
+ cap_hash = {}
try:
index_file = open(index_file_name, "r")
print "index file:", index_file.name, "[OPENED]",
@@ -107,14 +128,17 @@ def main():
print len(cap_hash), "files"
except IOError:
print "index file:", index_file_name, "[NEW]"
- cap_hash = {}
- if options.list_proto:
- list_proto(cap_hash)
+ if options.list_all_proto:
+ list_all_proto(cap_hash)
+ exit(0)
+
+ if options.list_all_files:
+ list_all_files(cap_hash)
exit(0)
- if options.list_files:
- list_files(cap_hash)
+ if options.list_all_proto_files:
+ list_all_proto_files(cap_hash, options.list_all_proto_files)
exit(0)
tshark = os.path.join(options.bin_dir, "tshark.exe")