Last active
February 4, 2021 08:56
-
-
Save peaceman/dc840e11c44fec1e9b317583a54a79d5 to your computer and use it in GitHub Desktop.
tcp connection test
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 | |
TARGET_HOST="$1" | |
TARGET_PORT="$2" | |
echo "starting tcpdump" | |
tcpdump -w "tcp-test-client_${TARGET_PORT}_%Y%m%d-%H%M%S.pcap" -G 3600 "ip6 and (src port $TARGET_PORT or dst port $TARGET_PORT)" & | |
TCPDUMP_PID=$! | |
function cleanup() | |
{ | |
echo "stopping tcpdump" | |
kill $TCPDUMP_PID | |
wait $TCPDUMP_PID | |
} | |
trap cleanup EXIT | |
while true; do | |
DATE=$(date) | |
NC_OUT=$(echo "$DATE" | nc -6v -w1 -N "$TARGET_HOST" "$TARGET_PORT" 2>&1) | |
echo "$DATE -> $NC_OUT" | |
sleep 5 | |
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
#!/usr/bin/env bash | |
LISTEN_HOST="$1" | |
LISTEN_PORT="$2" | |
echo "starting tcpdump" | |
tcpdump -w "tcp-test-server_${LISTEN_PORT}_%Y%m%d-%H%M%S.pcap" -G 3600 "ip6 and (src port $LISTEN_PORT or dst port $LISTEN_PORT)" & | |
TCPDUMP_PID=$! | |
function cleanup() | |
{ | |
echo "stopping tcpdump" | |
kill $TCPDUMP_PID | |
wait $TCPDUMP_PID | |
} | |
trap cleanup EXIT | |
echo "starting netcat on $LISTEN_PORT" | |
nc -klv -s "$LISTEN_HOST" -p "$LISTEN_PORT" 2>&1 | while read -r line; do | |
printf '%s -> %s\n' "$(date)" "$line" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment