Created
December 19, 2024 14:49
-
-
Save WietseWind/38734f75a03a4419aac5b8a7d589bd79 to your computer and use it in GitHub Desktop.
UDP fragmentation checker
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
#!/bin/bash | |
PORT=12345 | |
RESULTS_DIR="udp_receiver_results_$(date +%Y%m%d_%H%M%S)" | |
mkdir -p "$RESULTS_DIR" | |
echo "Starting UDP fragmentation test - Receiver" | |
echo "----------------------------------------" | |
echo "Port: $PORT" | |
echo "Results directory: $RESULTS_DIR" | |
# Log configuration | |
echo "Test Configuration" > "$RESULTS_DIR/receiver_config.log" | |
echo "----------------" >> "$RESULTS_DIR/receiver_config.log" | |
echo "Timestamp: $(date)" >> "$RESULTS_DIR/receiver_config.log" | |
echo "Port: $PORT" >> "$RESULTS_DIR/receiver_config.log" | |
echo "Timestamp,Source_IP,Expected_Size,Actual_Size,Size_Match,Data_Valid" > "$RESULTS_DIR/receiver_results.csv" | |
cleanup() { | |
echo -e "\nReceiver stopped. Results saved in $RESULTS_DIR/" | |
exit 0 | |
} | |
trap cleanup SIGINT SIGTERM | |
nc -6 -u -l -k $PORT | while read -r line; do | |
timestamp=$(date +"%Y-%m-%d %H:%M:%S.%N") | |
source_ip=$(netstat -nu | grep ":$PORT" | tail -1 | awk '{print $5}' | cut -d: -f1) | |
if [[ $line =~ ^[0-9]{8}: ]]; then | |
# Extract test packet information using string manipulation instead of numeric evaluation | |
expected_size="${line:0:8}" # Get as string, not number | |
actual_size=$((${#line} - 9)) | |
payload=${line:9} | |
# Compare sizes as decimal numbers | |
if [ "$actual_size" -eq "$((10#$expected_size))" ]; then | |
size_match="true" | |
else | |
size_match="false" | |
fi | |
# Verify payload contains valid base64 characters | |
if [[ "$payload" =~ ^[A-Za-z0-9+/=]+$ ]]; then | |
data_valid="true" | |
else | |
data_valid="false" | |
fi | |
echo "Received packet from $source_ip:" | |
echo " Expected size: $expected_size bytes" | |
echo " Actual size: $actual_size bytes" | |
echo " Size match: $size_match" | |
echo " Data valid: $data_valid" | |
echo "$timestamp,$source_ip,$expected_size,$actual_size,$size_match,$data_valid" >> "$RESULTS_DIR/receiver_results.csv" | |
else | |
# Handle regular messages | |
size=${#line} | |
echo "Received test message from $source_ip - Size: $size bytes" | |
echo "Content: $line" | |
echo "$timestamp,$source_ip,n/a,$size,n/a,n/a" >> "$RESULTS_DIR/receiver_results.csv" | |
fi | |
done |
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
#!/bin/bash | |
RECEIVER_IP="2a0xxxxxxxfb" | |
PORT=12345 | |
echo "Starting UDP MTU boundary test" | |
echo "---------------------------" | |
echo "Targeting: $RECEIVER_IP:$PORT" | |
# Test range around suspected MTU boundary | |
for size in $(seq 1400 10 1500); do | |
echo "Testing size: $size bytes..." | |
# Calculate base64 input size (3/4 of target) | |
raw_size=$((size * 3 / 4)) | |
# Create test data | |
random_data=$(head -c $raw_size /dev/urandom | base64) | |
actual_size=${#random_data} | |
data=$(printf "%08d:%s" $actual_size "$random_data") | |
echo "$data" | nc -6 -w 1 -u $RECEIVER_IP $PORT | |
sleep 1 | |
echo "-------------------------" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment