-
Notifications
You must be signed in to change notification settings - Fork 0
/
gather_probes
95 lines (76 loc) · 2.19 KB
/
gather_probes
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
#!/bin/bash
# Function to display help menu
display_help() {
echo "Usage: $0 [-e <input_file>]"
echo "Options:"
echo " -e, --exclude-file Specify the input file containing SSIDs to exclude (each SSID on a separate line)"
echo " -h, --help Display this help menu"
exit 1
}
# Function to clean up and exit
cleanup() {
echo -e "\nCleaning up..."
pkill -P $$
wait
rm -f /tmp/log.db # Remove the temporary log file
echo "Done."
exit 0
}
trap cleanup SIGINT SIGTERM
output_dir="/root/gprobes"
counter=1
excluded_ssids=""
while getopts ":e:h" opt; do
case $opt in
e)
input_file="$OPTARG"
;;
h)
display_help
;;
\?)
echo "Error: Invalid option -$OPTARG"
display_help
;;
:)
echo "Error: Option -$OPTARG requires an argument."
display_help
;;
esac
done
# Check if the input file is provided
if [ -z "$input_file" ]; then
echo "Error: No input file specified."
display_help
fi
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Error: Input file '$input_file' not found."
exit 1
fi
# Check if the directory already exists
if [ ! -d "$output_dir" ]; then
echo "Creating directory: $output_dir"
mkdir -p "$output_dir"
else
echo "Directory $output_dir already exists. Skipping."
fi
# Find the next available output file name
while [ -e "$output_dir/probes$counter.txt" ]; do
((counter++))
done
output_file="$output_dir/probes$counter.txt"
echo "Gathering All Probes within log.db"
echo "This might take some time if your log.db is big"
# Copy the current log.db to tmp
# Change to your log directory (default: /root/log.db)
cp /root/pinelogs/activity/log.db /tmp
# Constructing awk command to exclude SSIDs
awk_command="BEGIN { while (getline < \"$input_file\") { ssids[\$0] = 1 } }"
awk_command+=' { if ($3 in ssids) next; print $3 " | " $2 }'
sqlite3 /tmp/log.db "select * from log;" | awk -F '|' "$awk_command" | sort | uniq > "$output_file"
# Remove db from tmp
rm /tmp/log.db
# Echo Completed.
echo
echo "Completed! You can find your probes file in: $output_file"