Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def process_file(filename, protocol):
- output_filename = '{0}-{1}.pcap'.format(filename, protocol)
- stdout_filename = '{0}.stdout'.format(filename)
- stderr_filename = '{0}.stderr'.format(filename)
- exitcode_filename = '{0}.exitcode'.format(filename)
- cmdline = ['tshark', '-r', filename, '-Y', protocol, 'P', '-w', output_filename]
- print('Command line: {0}'.format(repr(cmdline)))
- stdout_file = open(stdout_filename, 'w')
- stderr_file = open(stderr_filename, 'w')
- exitcode_file = open(exitcode_filename, 'w')
- exit_code = None
- try:
- shell_cmdline = ' '.join(cmdline)
- process = subprocess.Popen(shell_cmdline,
- stdin=subprocess.PIPE,
- stdout=stdout_file,
- stderr=stderr_file,
- shell=True)
- process.stdin.close()
- exit_code = process.wait()
- except:
- # Exception raised while waiting on process; kill child process,
- # then re-raise exception.
- exit_code = process.poll()
- process.kill()
- raise
- finally:
- # These file handles should have been closed already, but it doesn't hurt
- # to close them again.
- stdout_file.close()
- stderr_file.close()
- exitcode_file.write('%s\n' % str(exit_code))
- exitcode_file.close()
- def thread_worker():
- while True:
- try:
- filename, protocol = global_q.get_nowait()
- print("Processing " + filename + "\n")
- process_file(filename, protocol)
- global_q.task_done()
- except queue.Empty:
- break
Add Comment
Please, Sign In to add comment