Skip to content

Instantly share code, notes, and snippets.

@nwithan8
Last active February 11, 2020 01:49
Show Gist options
  • Select an option

  • Save nwithan8/a86dad4b9f74f77d5ee218d97e862a08 to your computer and use it in GitHub Desktop.

Select an option

Save nwithan8/a86dad4b9f74f77d5ee218d97e862a08 to your computer and use it in GitHub Desktop.
Quickly ping multiple ports internally and externally to check if applications and/or services are up
IP="" # Internal IP address
EXTERNAL_ADDR="" # IP or URL (no http(s))
# Seperate items in list by spaces, not commas
# One service -> One port
SERVICES=(Service1 Service2 Service3)
PORTS=(80 443 32400)
# Example of different ways external address can be listed. Must be surrounded by quotes
# Port number should be included after a /.
# For basic websites, you still need to include /80 (http) or /443 (https)
EXTERNAL_SERVICES=(Service1 Service2 Service3)
EXTERNAL_ADDS=("example.com/80" "$EXTERNAL_ADDR/32400" "subdomain.$EXTERNAL_ADDR/443")
echo "Testing internal access:"
for ((i=0; i < ${#SERVICES[@]}; i++)); do
echo "$IP:${PORTS[i]}"
echo "${SERVICES[i]} $((echo >/dev/tcp/$IP/${PORTS[i]}) &>/dev/null && echo 'Up' || echo 'Down')"
done
echo ""
echo "Testing external access:"
for ((i=0; i < ${#EXTERNAL_SERVICES[@]}; i++)); do
echo "${EXTERNAL_ADDS[i]}"
echo "${EXTERNAL_SERVICES[i]} $((echo >/dev/tcp/${EXTERNAL_ADDS[i]}) &>/dev/null && echo 'Up' || echo 'Down')"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment