-
Notifications
You must be signed in to change notification settings - Fork 25
/
convert_pcap_csv.sh
executable file
·77 lines (50 loc) · 2 KB
/
convert_pcap_csv.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
#!/bin/bash
pcap_file="$1"
[[ ! -f "${pcap_file}" ]] && echo "PCAP file ${pcap_file} does NOT exist!" && exit 255
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # On the same directory.
echo ">>> Script dir: ${script_dir}"
output_dir="${script_dir}"/csv
## Clean
cancel() {
echo "+++ Converter is being canceled +++"
echo "+++ The last conversion, ${pcap_file}, is not completed!"
echo
exit 0
}
trap 'cancel' INT TERM
cleanup() {
# echo "+++ Remove ${pcap_file}"
# rm -f "${pcap_file}"
echo "+++ Finish the conversion"
echo
exit 0
}
trap 'cleanup' EXIT
## Convert
echo "+++ CICFlowMeter PCAP-to-CSV Converter +++"
echo " Input file: ${pcap_file}"
echo " Output dir: ${output_dir}"
# CICFlowMeter-3.0/bin/CICFlowMeter
# cic="${script_dir}"/CICFlowMeters/CICFlowMeter-3.0/bin/CICFlowMeter
cic="${script_dir}"/CICFlowMeters/CICFlowMeter-4.0/bin/CICFlowMeter
"${cic}" "${pcap_file}" "${output_dir}"
echo "+++ Remove ${pcap_file}"
rm -f "${pcap_file}"
## Rearrange the PCAP due to other CICFlowMeter versions' compatibility
# pcap_dir="${script_dir}"/tmp
# pcap_tmp="${pcap_dir}"/$(basename "${pcap_file}")
#echo "> move ${pcap_file} to ${pcap_tmp}"
#mv "${pcap_file}" "${pcap_dir}"
# CICFlowMeterV2
#cic_dir="${script_dir}"/CICFlowMeters/CICFlowMeterV2
#java -Djava.library.path="${cic_dir}" -jar "${cic_dir}"/CICFlowMeter.jar "${pcap_dir}/" "${output_dir}/2/"
#cic_dir=${HOME}/CICFlowMeterV2
#java -Djava.library.path="${cic_dir}/jnetpcap" -jar "${cic_dir}"/CICFlowMeter.jar "${pcap_dir}/" "${output_dir}/2/"
# CICFlowMeterV3-jnetpcap-1.3
#cic_dir="${script_dir}"/CICFlowMeters/CICFlowMeterV3-jnetpcap-1.3
#java -Djava.library.path="${cic_dir}" -jar "${cic_dir}"/CICFlowMeterV3.jar "${pcap_tmp}" "${output_dir}/3.1.3/"
# CICFlowMeterV3-jnetpcap-1.4
#cic_dir="${script_dir}"/CICFlowMeters/CICFlowMeterV3-jnetpcap-1.4
#java -Djava.library.path="${cic_dir}" -jar "${cic_dir}"/CICFlowMeterV3.jar "${pcap_tmp}" "${output_dir}/3.1.4/"
#echo "+++ remove ${pcap_tmp}"
#rm -f "${pcap_tmp}"