Skip to content

Instantly share code, notes, and snippets.

@atucom
Created May 5, 2022 21:51
Show Gist options
  • Save atucom/60c34f3ac5b686373ac6db7295309cbd to your computer and use it in GitHub Desktop.
Save atucom/60c34f3ac5b686373ac6db7295309cbd to your computer and use it in GitHub Desktop.
Check if IP/IP:Port is web port
#!/usr/bin/env bash
if [[ "$1" = '-h' ]] || [[ "$1" = '--help' ]] || [[ -z "$1" ]]; then
echo "Specify an IP:port to check if it's web and what protocol"
echo "this first checks https then http"
echo
echo "Example: $0 1.1.1.1:3040"
echo "or"
echo "Example: $0 1.1.1.1"
exit 1
else
TARGET_IP_PORT=${1}
if curl -m 3 -v -k https://${TARGET_IP_PORT} &> /dev/null; then
echo https://${TARGET_IP_PORT} is good
exit
fi
if curl -m 3 -v -k http://${TARGET_IP_PORT} &> /dev/null; then
echo http://${TARGET_IP_PORT} is good
exit
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment