Performs a request to https://canyouseeme.org and checks its output for success
31 lines
557 B
Bash
31 lines
557 B
Bash
#!/usr/bin/bash
|
|
|
|
MIN_PORT=1
|
|
MAX_PORT=65535
|
|
|
|
PORT=$1
|
|
|
|
if [ ! $PORT ]; then
|
|
echo "Usage: $0 <PORT>"
|
|
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 |