diff --git a/check-port-open/check-port-open.sh b/check-port-open/check-port-open.sh new file mode 100644 index 0000000..7c435fa --- /dev/null +++ b/check-port-open/check-port-open.sh @@ -0,0 +1,31 @@ +#!/usr/bin/bash + +MIN_PORT=1 +MAX_PORT=65535 + +PORT=$1 + +if [ ! $PORT ]; then + echo "Usage: $0 " + exit 10 +fi + +if [ $PORT -lt $MIN_PORT ] || [ $PORT -gt $MAX_PORT ]; then + echo "Port must be a number between $MIN_PORT and $MAX_PORT" + exit 11 +fi + +echo "Checking wether port $PORT is open" + +RESPONSE=$(curl -s -X POST --url https://canyouseeme.org -d port=$PORT) + +echo $RESPONSE | grep -i "I can see your service on" > /dev/null +SUCCESS=$? + +if [ $SUCCESS -eq 0 ]; then + echo "Port $PORT is open" + exit 0 +else + echo "Port $PORT is not open" + exit 1 +fi \ No newline at end of file