summaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorArthur Pavlov <arthur.pavlovs@mail.utoronto.ca>2018-11-22 02:48:15 +0000
committerArthur Pavlov <arthur.pavlovs@mail.utoronto.ca>2018-11-22 02:48:15 +0000
commitd60ed3e81972b95d60e4054ca331c91ef01dd760 (patch)
tree9d0d68124a814fdd46f5b09c96d4f2eb18fbfb99 /code
parentbe4dd6957e4a1c8f06588f8baa9f3f0772ec7c18 (diff)
adding py script
Diffstat (limited to 'code')
-rw-r--r--code/perpacket/parser.py35
1 files changed, 35 insertions, 0 deletions
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)))