From 6517c5400d2ec8786f3a7a702c8b6f8e502cb0ab Mon Sep 17 00:00:00 2001 From: Arthur Pavlov Date: Sun, 25 Nov 2018 19:56:12 -0500 Subject: rtt part 2 --- code/rtt/tcp_number_of_connections.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 code/rtt/tcp_number_of_connections.py (limited to 'code/rtt/tcp_number_of_connections.py') diff --git a/code/rtt/tcp_number_of_connections.py b/code/rtt/tcp_number_of_connections.py new file mode 100644 index 0000000..fa8abb1 --- /dev/null +++ b/code/rtt/tcp_number_of_connections.py @@ -0,0 +1,34 @@ +import csv + +flowsTCP = [] +with open('packetdata.csv', mode='r') as csv_file: + csv_reader = csv.DictReader(csv_file) + for row in csv_reader: + if row["Protocol"] == 'TCP': + tcpFlowExists = False + src = row["Source"] + dest = row["Destination"] + for flow in flowsTCP: + if src in flow and dest in flow: + tcpFlowExists = True + if row["Stream index"] not in flow[2]: + flow[2].append(row["Stream index"]) + break + if not tcpFlowExists: + flowsTCP.append([src, dest, [row["Stream index"]]]) + +csv_file.close() + +flowsTCPOut = [] + +for row in flowsTCP: + flowsTCPOut.append([row[0], row[1], len(row[2])]) + +with open('tcp_number_of_connections.csv', mode='w', newline='') as tcpConnections: + fieldnames = ['src', 'dest', 'connectionCount'] + writer = csv.DictWriter(tcpConnections, fieldnames=fieldnames) + writer.writeheader() + for flow in flowsTCPOut: + writer.writerow({'src': flow[0], 'dest': flow[1], 'connectionCount': flow[2]}) + +tcpConnections.close() -- cgit v1.2.3