1
0

feat: add script to check if a port is publicly accesible

Performs a request to https://canyouseeme.org and checks its output for success
This commit is contained in:
2025-05-11 21:40:13 +02:00
parent 602bce164d
commit 91b8808e27

View File

@@ -0,0 +1,31 @@
#!/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