From d60ed3e81972b95d60e4054ca331c91ef01dd760 Mon Sep 17 00:00:00 2001 From: Arthur Pavlov Date: Wed, 21 Nov 2018 21:48:15 -0500 Subject: adding py script --- code/perpacket/parser.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 code/perpacket/parser.py (limited to 'code/perpacket') diff --git a/code/perpacket/parser.py b/code/perpacket/parser.py new file mode 100644 index 0000000..422b699 --- /dev/null +++ b/code/perpacket/parser.py @@ -0,0 +1,35 @@ +import csv + +with open('packetdata.csv', mode='r') as csv_file: + csv_reader = csv.DictReader(csv_file) + line_count = 0 + flowsTCP = [] + flowsUDP = [] + for row in csv_reader: + if row["Protocol"] == 'TCP': + flowExists = False + src = row["Source"] + dest = row["Destination"] + srcPort = row["Info"].split(' > ')[0].split(' ')[0] + destPort = row["Info"].split(' > ')[1].split(' ')[1] + startTime = float(row["Time"]) + for flow in flowsTCP: + if src in flow and dest in flow and srcPort in flow and destPort in flow: + flowExists = True + break + if not flowExists: + flowsTCP.append([src, dest, srcPort, destPort, startTime, startTime]) + if row["Protocol"] == 'UDP': + flowExists = False + src = row["Source"] + dest = row["Destination"] + srcPort = row["Info"].split(' > ')[0].split(' ')[0] + destPort = row["Info"].split(' > ')[1].split(' ')[1] + for flow in flowsUDP: + if src in flow and dest in flow and srcPort in flow and destPort in flow: + flowExists = True + break + if not flowExists: + flowsUDP.append([src, dest, srcPort, destPort]) + print('TCP Length ' + str(len(flowsTCP))) + print('UDP Length ' + str(len(flowsUDP))) -- cgit v1.2.3