-
Notifications
You must be signed in to change notification settings - Fork 3
/
CodeFlowOld.sh
executable file
·302 lines (265 loc) · 9.83 KB
/
CodeFlowOld.sh
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
#Parent Folder of Scripts
home_dir=`eval echo ~$USER`
scripts_path=$home_dir"/Scripts/CausalAnalysis/"
logFile="log.txt"
pcap_parent=$home_dir"/Datasets_PCAPs/"
csv_parent=$home_dir"/Datasets_CSVs/"
separator="/"
underscore="_"
#specific scripts sub folder
aps_clients="APs-Clients/"
number_of_frames="FindNumberofFrames/"
frame_details="FindAllTrafficDetails/"
airtime_utilization="ATU/"
useless_pt="UselessProbeTraffic/"
causal_analysis="CausalAnalysis-Datasets/"
causal_analysis_dfa="CausalAnalysis-DFA/"
preq_pres="1PReq_NPRes/"
convert_pcap_csv="ConvertPCAPtoCSV/"
###########################################################
######Initial Choices######################################
###########################################################
echo -n "Name of dataset to be processed....."
read dataset
echo -n "EDCA Enabled(1) or Disabled(0)?..Enter 1 or 0..."
read edcaEnabled
echo -n "Header - Radiotap(1) or Prism(2)..Enter 1 or 2....."
read denominator
echo "What do you want to process?..Enter Y or N..."
echo
echo -n ".....Convert PCAP to CSV required?....."
read convert
echo -n ".....APs and Clients?....."
read findAPsClients
echo -n ".....Filter Traffic?....."
read filterTraffic
echo -n ".....Frame Details?....."
read frameDetails
echo -n ".....Airtime Utilization?....."
read atu
if echo "$atu" | grep y
then
echo -n "..........Enter Slot Size (seconds) for Calculating Airtime Utilization....."
read slotSize
fi
echo -n ".....Useless Probe Traffic?....."
read upt
echo -n ".....Automatic Causal Detection?....."
read acd
#if echo "$upt" | grep y
#then
#fi
echo -n ".....Quantify Causes?....."
read quantifyCauses
echo -n ".....Find 1 Probe Request = X Probe Responses?....."
read preqNpres
######################################################
#####################End##############################
######################################################
echo "Scripts Path...." $scripts_path
#PCAP Folder Structure: /home/dherytaj/Datasets_PCAPs/Name_of_dataset/DayNo/<PCAP_Files>
pcap_path=$pcap_parent$dataset
#CSV Folder Structure: ~/Datasets_CSVs/Name_of_dataset/DayNo_Merged.csv
csv_path=$csv_parent$dataset
#Convert PCAPs to CSVs, Merge CSVs to Merged.csv
mkdir -p $csv_path
if echo "$convert" | grep y
then
i=1
echo "PCAP PATH:" $pcap_path
for date in `ls -v $pcap_path/`; do
echo "Processing Date:" $date
process_folder=$pcap_path$separator$date$separator
#Convert PCAP to CSV will create two folders PCAP_CSV and Merged in Date Folder, we need to move Merged/Merged.csv to CSV Folder Structure given below
execute_path=$scripts_path$convert_pcap_csv
script_name="/ConvertPCAPtoCSV.sh"
echo "Processing Folder: " $process_folder
$execute_path$script_name $process_folder
merged="Merged.csv"
filename=Day$i$underscore$merged
mv $process_folder/Merge/Merge.csv $csv_path$separator$filename
i=`expr $i + 1`
done
echo "Conversion Complete"
fi
#number_of_days=`ls -l| wc -l`
#number_of_days=`expr $number_of_days - 1` #These many folders will be created
echo "Creating Folder Structure"
#Output Folder Structure: ~/DataAnalysis/Name_of_dataset/Day#/ScriptName/
output_parent="/home/dherytaj/DataAnalysis/"
output_path=$output_parent$dataset$separator
#Create Folder Structure
if [ ! -d $output_path ]; then
mkdir $output_path
fi
for csv in `ls -v $csv_path`; do #One folder per day of data
#Format Day#_Merged.csv
day=`echo $csv|tr '_' ','|awk -F, '{print $1}'`
echo "Creating folders for:" $csv " and " $day
datanalysis_path=$output_path$separator$day$separator
echo "Data Analysis Path:" $datanalysis_path
#For every script create one folder
if [ ! -d $datanalysis_path ]; then
mkdir $datanalysis_path
fi
mkdir -p $datanalysis_path$aps_clients
mkdir -p $datanalysis_path$number_of_frames
mkdir -p $datanalysis_path$frame_details
mkdir -p $datanalysis_path$airtime_utilization
mkdir -p $datanalysis_path$useless_pt
mkdir -p $datanalysis_path$causal_analysis
mkdir -p $datanalysis_path$causal_analysis_dfa
mkdir -p $datanalysis_path$preq_pres
done
echo "Folder Structure Created"
askUPT_Everytime=
askCausal_Everytime=
echo "Processing Started"
#For every Merged.csv of every dataset
for csv in `ls $csv_path/`; do
day=`echo $csv|tr '_' ','|awk -F, '{print $1}'`
echo "..Processing day: $day"
if echo "$findAPsClients" | grep y
then
echo "....Find APs and Clients--Started"
out_path=$output_path$day$separator$aps_clients$separator
execute_path=$scripts_path$aps_clients
script_name="/FindAPs-Clients.sh"
$execute_path$script_name $csv_path$separator$csv $out_path
echo "......***Please manually remove spurious entries from SSIDs.txt***...."
echo "....Find APs and Clients--Ended"
fi
if echo "$filterTraffic" | grep y
then
echo "....Find number of total, data, management, and control frames--Started"
out_path=$output_path$day$separator$number_of_frames$separator
execute_path=$scripts_path$number_of_frames
script_name="/FilterTraffic.sh "
$execute_path$script_name $csv_path$separator$csv $out_path
echo "....Find number of total, data, management, and control frames--Ended"
fi
if echo "$frameDetails" | grep y
then
echo "....Find CDF size, rate, IFAT of probe requests, probe response, probe traffic, data and ack--Started"
out_path=$output_path$day$separator$frame_details$separator
execute_path=$scripts_path$frame_details
script_name="/ConsolidatedFrameDetails.sh "
$execute_path$script_name $csv_path$separator$csv $out_path $denominator
echo "....Find CDF size, rate, IFAT of probe requests, probe response, probe traffic, data and ack--Ended"
fi
if echo "$atu" | grep y
then
echo "....Find airtime utilization of probe requests, probe responses, and ACKs--Started"
out_path=$output_path$day$separator$airtime_utilization$separator
execute_path=$scripts_path$airtime_utilization
script_name="/ProcessPCAPsForATU.sh "
$execute_path$script_name $csv_path$separator$csv $out_path $edcaEnabled $denominator $slotSize
echo "....Find airtime utilization of probe requests, probe responses, and ACKs--Ended"
fi
if echo "$upt" | grep y
then
echo "....Find useless probe traffic--Started"
out_path=$output_path$day$separator$useless_pt$separator
execute_path=$scripts_path$useless_pt
script_name="/FindUPT.sh"
if [ -z "$askUPT_Everytime" -o "$askUPT_Everytime" = "y" ]; then
echo -n "........Do you want to provide path of clients file (1) or enter client MAC addresses (2)?"
read clientChoice
if [ $clientChoice -eq 1 ]; then
echo -n "........Enter the file name----"
read clientFile
fi
if [ $clientChoice -eq 2 ]; then
enterMore=
until [ "$enterMore" = "n" ]; do
echo -n ".........Client's MAC Address----"
read clientMAC
clientFile="/tmp/Clients.txt"
if [ -f $clientFile ]; then
rm $clientFile
fi
echo $clientMAC >> $clientFile
echo -n "..........Enter More (y/n)?"
read enterMore
done
fi
echo -n "........Enter allowed SSIDs (CSV)----"
read SSIDs
ssidFile="/tmp/SSIDs.txt"
if [ -f $ssidFile ]; then
rm $ssidFile
fi
echo $SSIDs >> $ssidFile
fi
if [ -z "$askUPT_Everytime" ]; then
echo -n "......Do you want to enter clients and ssids next time? (y-yes, n-no)......"
read askUPT_Everytime
fi
$execute_path$script_name $csv_path$separator$csv $out_path $ssidFile $clientFile
echo "....Find useless probe traffic--Ended"
fi
if echo "$quantifyCauses" | grep y
then
echo "....Find the quantification of causal model--Started"
out_path=$output_path$day$separator$causal_analysis$separator
execute_path=$scripts_path$causal_analysis
script_name="/Quantify-Causes.sh"
if [ -z "$askCausal_Everytime" -o "$askCausal_Everytime" = "y" ]; then
echo -n "........Do you want to provide path of clients file (1) or enter client MAC addresses (2)?"
read clientChoice
if [ $clientChoice -eq 1 ]; then
echo -n "........Enter the file name----"
read clientFile
fi
if [ $clientChoice -eq 2 ]; then
enterMore=
until [ "$enterMore" = "n" ]; do
echo -n ".........Client's MAC Address----"
read clientMAC
clientFile="/tmp/Clients.txt"
if [ -f $clientFile ]; then
rm $clientFile
fi
echo $clientMAC >> $clientFile
echo -n "..........Enter More (y/n)?"
read enterMore
done
fi
fi
if [ -z "$askCausal_Everytime" ]; then
echo -n "......Do you want to enter clients next time? (y-yes, n-no)......"
read askCausal_Everytime
fi
ssidFile=$output_path$day$separator$aps_clients/SSIDs.txt
if [ -f $ssidFile ]; then
$execute_path$script_name $csv_path$separator$csv $out_path $clientFile $ssidFile
echo "....Find the quantification of causal model--Ended"
else
echo "....Find the quantification of causal model--Failed - Create SSID File"
fi
fi
if echo "$acd" | grep y
then
echo "....Automatic Causal Detection--Started"
out_path=$output_path$day$separator$causal_analysis_dfa$separator
execute_path=$scripts_path$causal_analysis_dfa
script_name="/Prepare_Data_F_Signatures.sh"
echo -n "....Enter AP MAC...."
read ap_mac
echo -n "....Enter AP SSID...."
read ap_ssid
$execute_path$script_name $csv_path$separator$csv $out_path $ap_mac $ap_ssid
echo "....Automatic Causal Detection--Ended"
fi
if echo "$preqNpres" | grep y
then
echo "....Find 1 probe request is responded by how many probe responses--Started"
out_path=$output_path$day$separator$preq_pres$separator
execute_path=$scripts_path$preq_pres
script_name="/Find1PreqNPres.sh"
$execute_path$script_name $csv_path$separator$csv $out_path
echo "....Find 1 probe request is responded by how many probe responses--Ended"
fi
done
echo "Processing Completed"