hehe
🧩 Syntax:
#!/bin/bash
# Define the port to listen on
PORT=12345
# Start an infinite loop to listen for incoming connections
while true; do
# Use netstat to determine the IP address of the sender
SENDER_IP=$(netstat -tn 2>/dev/null | awk '/'"$PORT"'/ {print $5}' | cut -d: -f1 | head -n1)
# Listen on the specified port and capture the input without DNS lookups
INPUT=$(nc -l -p $PORT)
# Print debugging information
echo "Received input: $INPUT"
echo "Sender's IP address: $SENDER_IP"
# Check if the received input matches the expected inputs
case "$INPUT" in
"Hello")
# Send the response message back to the sender
echo "World" | nc -q 0 $SENDER_IP $PORT
;;
"Goodbye")
# Send the response message back to the sender
echo "Farewell" | nc -q 0 $SENDER_IP $PORT
;;
*)
# Send an unrecognized input message
echo "Unrecognized input" | nc -q 0 $SENDER_IP $PORT
;;
esac
done