This repository was archived by the owner on Jan 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathalign_pcap_to_today.sh
More file actions
executable file
·64 lines (48 loc) · 1.6 KB
/
Copy pathalign_pcap_to_today.sh
File metadata and controls
executable file
·64 lines (48 loc) · 1.6 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
#!/usr/bin/env bash
PCAP_IN=$1
PCAP_OUT=$2
INTERVAL=86400
function __help()
{
echo "Usage: $0 input_pcap output_pcap"
echo "The first 24 hours of data from input_pcap will be aligned to the current day in output_pcap"
exit
}
if [ "$PCAP_IN" = "-h" -o "$PCAP_IN" = "--help" -o -z "$PCAP_IN" -o -z "$PCAP_OUT" ]; then
__help
fi
# Create a temporary directory to work in
WORK_DIR=`mktemp -d` || exit 1 # Exit if we can't get the temp dir
editcap -i $INTERVAL "$PCAP_IN" "$WORK_DIR/$(basename $PCAP_IN)"
INTERVAL_FILES=`find $WORK_DIR -maxdepth 1 -type f`
NUM_INTERVAL_FILES=`echo "$INTERVAL_FILES" | wc -l`
if [ $NUM_INTERVAL_FILES -gt 1 ]; then
echo "$(basename $PCAP_IN) consists of multiple 24H intervals."
echo "Which interval would you like to use?"
echo "NOTE: The last interval may not contain a full 24H capture."
while [ -z "$INTERVAL_PCAP" ]; do
echo ""
echo "$(basename $PCAP_IN) contained $NUM_INTERVAL_FILES intervals."
for file in $INTERVAL_FILES; do
printf "\t$(basename $file)\n"
done
for file in $INTERVAL_FILES; do
echo ""
capinfos -aecst "$file"
read -p "Align $(basename $file) to today? (y/n) [n] " -r
if [[ "$REPLY" =~ ^[Yy] ]]; then
INTERVAL_PCAP="$file"
echo ""
break
fi
done
done
fi
CURR_DATE=`date -I`
LAST_MIDNIGHT_TS=`date +%s --date="$CURR_DATE"`
INTERVAL_PCAP_DATE=`capinfos $INTERVAL_PCAP | grep 'First packet time' | cut -d' ' -f6-`
INTERVAL_PCAP_TS=`date +%s --date="$INTERVAL_PCAP_DATE"`
TS_OFFSET=`expr $LAST_MIDNIGHT_TS - $INTERVAL_PCAP_TS`
echo "Writing out $PCAP_OUT"
editcap -t $TS_OFFSET "$INTERVAL_PCAP" "$PCAP_OUT"
rm -rf "$WORK_DIR"