#! /usr/local/bin/python # # merges tshark statistics and adds full unix-timestamps # # Filenames/Arguments: # Output filename is hard-coded. # # Names of PCAP files are read from command line. # # for every PCAP file a ${file}.stat file is expected, to be created with # tshark -r $file -nqz io,stat,... > ${file}.stat import sys,subprocess,time outfile = open("combined_data", "w") for fname in sys.argv[1:]: print "processing %s..." % fname cmd = "nice capinfos -a %s | tail -1" % fname out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] timetext = out[13:-1] timetuple = time.strptime(timetext.strip()) timestamp = time.mktime(timetuple) cmd = "grep '^[0-9]' %s" % (fname + ".stat") out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] data = [x.split() for x in out.split("\n")] for n in range(len(data)): # remove empty lines/tuples if len(data[n]) == 0: del(data[n]) for line in data: offset = int(line[0].split(".")[0]) ts = timestamp + offset line[0] = str(int(ts)) writeline = " ".join(line) outfile.write(writeline + "\n") outfile.close()