-
Notifications
You must be signed in to change notification settings - Fork 4
/
uniq_ips.sh
executable file
·38 lines (29 loc) · 1.14 KB
/
uniq_ips.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
#!/usr/bin/env bash
dir="$1"
output_dir="$2"
if [[ ! -d "$dir" ]] || [[ ! -d "$output_dir" ]] ; then
printf "Usage: `basename $0` location of pcaps location to output logfiles\n "
echo "Searches a pcap file for uniq ip addresses and ranges"
exit 0
fi
function unique_fulloutput {
while read -r; do
printf '%s %s %s %s\n' 'Reading network traffic from' "$REPLY" 'Time Started:' "$(date +'%D %T')"
printf '%s\n\n' '#############################'
~/scripts/ip_dst_src.py "$REPLY"
done < <(find "$dir" -type f -iname '*.pcap') | tee -a ${output_dir}/uniq_ips_fulloutput.txt
printf '%s\n\n' '###########################'
printf '%s %s\n' 'Time Finished:' "$(date +'%D %T')"
}
function unique_ips {
awk '{print $1}' ${output_dir}/uniq_ips_fulloutput.txt|sort -n |sort -u|grep -v "Reading"|tee -a ${output_dir}/uniq_ips.txt
}
function unique_ranges {
awk '{print $3}' ${output_dir}/uniq_ips_fulloutput.txt|sort -n |sort -u|grep -v "traffic"|tee -a ${output_dir}/uniq_ranges.txt
}
function main {
unique_fulloutput "$dir" "$output_dir"
unique_ips "$output_dir"
unique_ranges "$output_dir"
}
main