Skip to content

Instantly share code, notes, and snippets.

@etyp
Last active December 7, 2023 09:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save etyp/dc9a9c620cc66f8d0344979e118b1721 to your computer and use it in GitHub Desktop.
Save etyp/dc9a9c620cc66f8d0344979e118b1721 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Send TCP dumps to S3
die() { status=$1; shift; echo "FATAL: $*"; exit $status; }
# Replace with actual bucket name
BUCKET_NAME="my-bucket";
# Get instance id
INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die \"wget instance-id has failed: $?\"`"
# Init temp file
touch temp.pcap
while true :
do
# Capture 5k packets
sudo tcpdump -i eth0 -w temp.pcap -c 5000 port 80
# Build filename
YEAR=$(date +%Y);
MONTH=$(date +%m);
DAY=$(date +%d);
HOUR=$(date +%H);
MINUTE=$(date +%M);
S3_KEY="s3://${BUCKET_NAME}/${INSTANCE_ID}/${YEAR}/${MONTH}/${DAY}/${HOUR}:${MINUTE}-${INSTANCE_ID}.pcap";
# Upload file to bucket with date
echo "Writing temp.pcap to ${S3_KEY}"
aws s3 cp --quiet temp.pcap $S3_KEY
# Clear temp pcap
rm -f temp.pcap
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment