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:
31
check-port-open/check-port-open.sh
Normal file
31
check-port-open/check-port-open.sh
Normal 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
|
Reference in New Issue
Block a user