-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata_processor_IP_ID.py
More file actions
86 lines (77 loc) · 3.32 KB
/
Copy pathdata_processor_IP_ID.py
File metadata and controls
86 lines (77 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
__author__ = "Md. Ahsan Ayub"
__license__ = "GPL"
__credits__ = ["Ayub, Md. Ahsan", "Smith, Steven", "Siraj, Ambareen",
"Hope, Shelby"]
__maintainer__ = "Md. Ahsan Ayub"
__email__ = "mayub42@students.tntech.edu"
__status__ = "Prototype"
# Importing the libraries
import numpy as np
import pandas as pd
import json
'''
Structure of the JSON dataset:
1st Layer node = 4
- Key = _index, _score, _source and _type
2nd Layer of interest is _source | node = 4
- Key = _eth, frame, ip and tcp
3rd Layer of interet is ip | key =
- Key = ip.hdr_len, ip.len, ip.id, ip.flags, ip.checksum, ip.checksum.status, ip.flags.rb, ip.flags.df,
ip.flags.mf, ip.frag_offset, ip.ttl, ip.proto
'''
# Initializing the globals
columnName = ['ip.hdr_len', 'ip.len', 'ip.id', 'ip.flags', 'ip.checksum', 'ip.checksum.status', 'ip.flags.rb', 'ip.flags.df', 'ip.flags.mf', 'ip.frag_offset', 'ip.ttl', 'ip.proto', 'class']
mainDataFrame = np.ndarray([100000,13])
mainDataFrame = mainDataFrame.astype(str)
temp = ['nan' for i in range(13)]
rowIndexToInsertNDArray = 0
# Index Checking of the existing column
def checkColumnName(key):
for i in range(0, 13):
if (key == columnName[i]):
return i # returning the existing value index
return -1 # if no item exists
def loadToMainDataFrame():
for i in range(13):
if(temp[i] == 'nan'):
mainDataFrame[rowIndexToInsertNDArray][i] = np.nan
else:
mainDataFrame[rowIndexToInsertNDArray][i] = temp[i]
# Parsing data from the production JSON dataset
data = json.load(open("./Regular_Network_Traffic.json"))
for data_dic in data:
for key in data_dic:
if (key == '_source'):
for key_2nd_Layer in data_dic[key]['layers']:
if (key_2nd_Layer == 'ip'):
for final_key in data_dic[key]['layers'][key_2nd_Layer]:
if(final_key == 'ip.dsfield_tree'):
continue
elif(final_key == 'ip.flags_tree'):
for flags_tree in data_dic[key]['layers'][key_2nd_Layer][final_key]:
index = checkColumnName(flags_tree)
if (index == -1):
continue
else:
temp[index] = data_dic[key]['layers'][key_2nd_Layer][final_key][flags_tree]
else:
index = checkColumnName(final_key)
if (index == -1):
continue
else:
temp[index] = data_dic[key]['layers'][key_2nd_Layer][final_key]
else:
continue
# hard coded class defined
'''if (temp[2] == '0x00002000'):'''
temp[12] = 1 # Covert channel's presence
'''else:
temp[12] = 0 # No Covert channel's presence'''
loadToMainDataFrame()
rowIndexToInsertNDArray = rowIndexToInsertNDArray + 1
temp.clear()
temp = ['nan' for i in range(13)]
else:
continue
# Generating the CSV file for further usuage.
pd.DataFrame(mainDataFrame).to_csv("Processed_Data_Set_IP_ID_22_10_2018.csv")