# Created on savesnippets.com · https://savesnippets.com/daGwhnHMQoLYNY # Method 1: nc (netcat) — universal nc -z -w 3 host.example.com 443 && echo "open" || echo "closed" # Method 2: pure bash via /dev/tcp (no deps — but bash-only, not POSIX sh) if timeout 3 bash -c "echo > /dev/tcp/host.example.com/443"; then echo "open" fi # Method 3: curl for an HTTPS endpoint curl -fsSL --connect-timeout 3 https://host.example.com >/dev/null && echo "HTTPS OK" # Reusable helper port_open() { timeout 3 bash -c "echo > /dev/tcp/$1/$2" 2>/dev/null } port_open google.com 443 && echo "Google HTTPS reachable" port_open localhost 5432 || echo "Postgres NOT running"