Skip to content

Instantly share code, notes, and snippets.

@peaceman
Last active February 4, 2021 08:56
Show Gist options
  • Save peaceman/dc840e11c44fec1e9b317583a54a79d5 to your computer and use it in GitHub Desktop.
Save peaceman/dc840e11c44fec1e9b317583a54a79d5 to your computer and use it in GitHub Desktop.
tcp connection test
#!/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
#!/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