diff options
| author | Arthur Pavlov <arthur.pavlovs@mail.utoronto.ca> | 2018-11-26 00:56:12 +0000 |
|---|---|---|
| committer | Arthur Pavlov <arthur.pavlovs@mail.utoronto.ca> | 2018-11-26 00:56:12 +0000 |
| commit | 6517c5400d2ec8786f3a7a702c8b6f8e502cb0ab (patch) | |
| tree | 6831b681ede24a05800c4433cfc1fdb096fba792 /code/rtt/tcp_number_of_connections.py | |
| parent | fe7a6e58b1ec124a26a415364f17a012e42334c5 (diff) | |
rtt part 2
Diffstat (limited to 'code/rtt/tcp_number_of_connections.py')
| -rw-r--r-- | code/rtt/tcp_number_of_connections.py | 34 |
1 files changed, 34 insertions, 0 deletions
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() |
