Last active
March 2, 2021 16:35
-
-
Save pocc/cdf578a757be3a5b13b5e3bfc0fc2f82 to your computer and use it in GitHub Desktop.
Live capture a Chrome or Firefox pcap/ng download as it is downloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script will detect if there are any new partial download files | |
# And launch wire/tshark to read them as a live capture. | |
DL_DIR="$HOME/Downloads" | |
SHARK_CMD="wireshark -k -i -" | |
# SHARK_CMD="tshark -r -" | |
function DL_PARTIALS { | |
# Partial names: Chrome=$file.crdownload, Firefox=$file.part, Safari=$file.download, Edge=$file.RaNd0mStr.partial | |
find "$DL_DIR" -maxdepth 1 | perl -ne 'print /(.*pcapng\.(part|crdownload|download|[a-zA-Z0-9]+\.partial))/' | |
} | |
while true; do | |
file="$(DL_PARTIALS)" | |
while [ "$file" = "" ]; do sleep 1; file="$(DL_PARTIALS)"; done | |
# Don't reopen wireshark if the user closed it for this file | |
if [ "$prev_file_id" != "$(stat -c %i $file)" ]; then | |
echo "Found download partial \`$file\`" | |
tail -f -n +1 $file | $SHARK_CMD | |
else | |
sleep 1 | |
fi | |
prev_file_id="$(stat -c %i $file)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment