2015-05-19 13:26:10 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
|
|
|
|
from subprocess import check_output
|
|
|
|
import csv
|
|
|
|
|
|
|
|
from io import StringIO
|
2015-05-26 19:00:03 +00:00
|
|
|
import re
|
2015-05-27 17:59:35 +00:00
|
|
|
import numpy as np
|
2015-05-26 19:00:03 +00:00
|
|
|
|
2015-05-19 13:26:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TcptraceData:
|
|
|
|
def __init__(self, pcap_file):
|
|
|
|
self.pcap_file=pcap_file
|
|
|
|
csv_content = check_output(["tcptrace", "-l", "--csv", pcap_file])
|
|
|
|
tcptrace_reader = csv.reader(filter(lambda l: len(l)>0 and l[0]!="#",csv_content.splitlines()))
|
2015-05-27 17:59:35 +00:00
|
|
|
cells=np.array(list(tcptrace_reader))
|
|
|
|
#drop header row
|
|
|
|
cells= cells[1:]
|
|
|
|
self.cells = cells
|
2015-05-19 13:26:10 +00:00
|
|
|
self.headers=cells[0]
|
|
|
|
self.flows=cells[1:]
|
|
|
|
self.number_of_flows=len(self.flows)
|
2015-05-27 17:59:35 +00:00
|
|
|
def get_csv(self, name):
|
|
|
|
return self.cells
|