Created
September 29, 2025 20:59
-
-
Save mavieth/109c16f2ea75da7bedfccc2149064bde to your computer and use it in GitHub Desktop.
Check united wifi URL's for availability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # check_united_wifi_open.sh | |
| # Probes endpoints and opens the first one that returns HTTP 200 (then exits). | |
| # Usage: | |
| # ./check_united_wifi_open.sh # uses built-in endpoints | |
| # ./check_united_wifi_open.sh -f file.txt # use custom endpoint list (one per line) | |
| # ./check_united_wifi_open.sh -t 5 # adjust timeout (seconds) | |
| set -eo pipefail | |
| # Color codes | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[0;33m' | |
| BLUE='\033[0;34m' | |
| CYAN='\033[0;36m' | |
| BOLD='\033[1m' | |
| RESET='\033[0m' | |
| TIMEOUT=5 | |
| USER_AGENT="curl-united-wifi-check/1.0" | |
| ENDPOINTS_FILE="" | |
| # default endpoints (edit as you like) | |
| ENDPOINTS=( | |
| "http://connect.united.com" | |
| "http://unitedwifi.com" | |
| "http://www.unitedwifi.com" | |
| "http://captive.apple.com" | |
| "http://www.apple.com" | |
| "http://1.1.1.1" | |
| "http://192.168.1.1" | |
| ) | |
| while getopts ":f:t:" opt; do | |
| case ${opt} in | |
| f) | |
| ENDPOINTS_FILE="$OPTARG" | |
| if [[ ! -f "$ENDPOINTS_FILE" ]]; then | |
| echo -e "${RED}Error: Endpoint file not found: $ENDPOINTS_FILE${RESET}" >&2 | |
| exit 2 | |
| fi | |
| mapfile -t ENDPOINTS < <(sed -n 's/^[[:space:]]*#.*//; /^[[:space:]]*$/d; p' "$ENDPOINTS_FILE") | |
| ;; | |
| t) TIMEOUT="$OPTARG" ;; | |
| \?) echo -e "${RED}Error: Invalid option -$OPTARG${RESET}" >&2; exit 2 ;; | |
| esac | |
| done | |
| # platform open command | |
| detect_and_open() { | |
| local url="$1" | |
| if command -v open >/dev/null 2>&1; then | |
| open "$url" | |
| elif command -v xdg-open >/dev/null 2>&1; then | |
| xdg-open "$url" | |
| else | |
| echo -e "${YELLOW}⚠️ No known opener (open/xdg-open) found. Please open this URL manually:${RESET} ${CYAN}$url${RESET}" | |
| return 2 | |
| fi | |
| } | |
| # Ensure endpoint has scheme | |
| ensure_scheme() { | |
| local u="$1" | |
| if [[ ! "$u" =~ ^https?:// ]]; then | |
| echo "http://$u" | |
| else | |
| echo "$u" | |
| fi | |
| } | |
| echo -e "\n${BOLD}${BLUE}═══════════════════════════════════════════════════════════${RESET}" | |
| echo -e "${BOLD}${CYAN} United WiFi Connectivity Check${RESET}" | |
| echo -e "${BOLD}${BLUE}═══════════════════════════════════════════════════════════${RESET}\n" | |
| echo -e "${CYAN}📡 Probing ${BOLD}${#ENDPOINTS[@]}${RESET}${CYAN} endpoints (timeout: ${BOLD}${TIMEOUT}s${RESET}${CYAN})${RESET}" | |
| echo -e "${BLUE}───────────────────────────────────────────────────────────${RESET}" | |
| for i in "${!ENDPOINTS[@]}"; do | |
| raw="${ENDPOINTS[$i]}" | |
| endpoint=$(ensure_scheme "$raw") | |
| printf "\n${BOLD}[%d/%d]${RESET} ${CYAN}Probing:${RESET} %s\n" $((i+1)) ${#ENDPOINTS[@]} "$endpoint" | |
| # Try HEAD (fast). Capture HTTP code and effective URL after redirects. | |
| # curl -sS -I -L -o /dev/null -w "%{http_code} %{url_effective}" | |
| head_out=$(curl -sS -I -L -m "$TIMEOUT" -A "$USER_AGENT" -o /dev/null -w "%{http_code} %{url_effective}" "$endpoint" 2>&1) || head_status=$? | |
| # If curl failed (non-zero) head_out may be empty | |
| if [[ -n "${head_out:-}" ]]; then | |
| http_code=$(echo "$head_out" | awk '{print $1}') | |
| effective_url=$(echo "$head_out" | awk '{print $2}') | |
| else | |
| http_code="000" | |
| effective_url="$endpoint" | |
| fi | |
| if [[ "$http_code" == "200" ]]; then | |
| echo -e " ${GREEN}HEAD → HTTP ${BOLD}$http_code${RESET} ${GREEN}Final URL: $effective_url${RESET}" | |
| elif [[ "$http_code" == "000" ]]; then | |
| echo -e " ${RED}HEAD → Timeout/Failed${RESET} ${RED}Final URL: $effective_url${RESET}" | |
| else | |
| echo -e " ${YELLOW}HEAD → HTTP ${BOLD}$http_code${RESET} ${YELLOW}Final URL: $effective_url${RESET}" | |
| fi | |
| if [[ "$http_code" == "200" ]]; then | |
| echo -e " ${GREEN}${BOLD}✅ SUCCESS!${RESET} ${GREEN}Got HTTP 200 from HEAD request${RESET}" | |
| echo -e " ${CYAN}🌐 Opening browser:${RESET} ${BOLD}$effective_url${RESET}" | |
| echo -e "\n${BLUE}═══════════════════════════════════════════════════════════${RESET}" | |
| detect_and_open "$effective_url" || true | |
| exit 0 | |
| fi | |
| # If HEAD didn't give 200, try GET and still check final status code (some captive portals behave differently) | |
| echo -e " ${CYAN}↻ Trying GET request...${RESET}" | |
| # request and capture final status and effective URL; limit body read via -m + piping to head -c | |
| # We'll fetch headers with -sS -D - to avoid dumping big bodies; using -L for redirects | |
| # Use curl write-out for code & url, but also cap body to first 200KB | |
| tmp_body="$(mktemp)" | |
| # Fetch body (first 200KB) to tmp_body; ignore curl non-zero exit but still read write-out | |
| curl -sS -L -m "$TIMEOUT" -A "$USER_AGENT" "$endpoint" --max-redirs 10 2>/dev/null | head -c $((200*1024)) > "$tmp_body" || true | |
| get_out=$(curl -sS -L -m "$TIMEOUT" -A "$USER_AGENT" -o /dev/null -w "%{http_code} %{url_effective}" "$endpoint" 2>/dev/null) || true | |
| if [[ -n "${get_out:-}" ]]; then | |
| http_code=$(echo "$get_out" | awk '{print $1}') | |
| effective_url=$(echo "$get_out" | awk '{print $2}') | |
| else | |
| http_code="000" | |
| effective_url="$endpoint" | |
| fi | |
| if [[ "$http_code" == "200" ]]; then | |
| echo -e " ${GREEN}GET → HTTP ${BOLD}$http_code${RESET} ${GREEN}Final URL: $effective_url${RESET}" | |
| elif [[ "$http_code" == "000" ]]; then | |
| echo -e " ${RED}GET → Timeout/Failed${RESET} ${RED}Final URL: $effective_url${RESET}" | |
| else | |
| echo -e " ${YELLOW}GET → HTTP ${BOLD}$http_code${RESET} ${YELLOW}Final URL: $effective_url${RESET}" | |
| fi | |
| if [[ "$http_code" == "200" ]]; then | |
| echo -e " ${GREEN}${BOLD}✅ SUCCESS!${RESET} ${GREEN}Got HTTP 200 from GET request${RESET}" | |
| echo -e " ${CYAN}🌐 Opening browser:${RESET} ${BOLD}$effective_url${RESET}" | |
| echo -e "\n${BLUE}═══════════════════════════════════════════════════════════${RESET}" | |
| detect_and_open "$effective_url" || true | |
| rm -f "$tmp_body" | |
| exit 0 | |
| fi | |
| # Optional: quick sniff of body for captive keywords to help debugging | |
| if [[ -s "$tmp_body" ]]; then | |
| if grep -qiE 'login|sign ?in|captive|portal|united|wifi|hotspot' "$tmp_body"; then | |
| echo -e " ${YELLOW}⚠️ Body contains captive portal keywords${RESET}" | |
| else | |
| echo -e " ${CYAN}ℹ️ Body doesn't appear to be a captive portal${RESET}" | |
| fi | |
| else | |
| echo -e " ${RED}✗ No body content captured${RESET}" | |
| fi | |
| rm -f "$tmp_body" | |
| done | |
| echo -e "\n${BLUE}───────────────────────────────────────────────────────────${RESET}" | |
| echo -e "${RED}${BOLD}❌ Connection Failed${RESET}" | |
| echo -e "${RED}No endpoint returned HTTP 200. Network may be unavailable.${RESET}" | |
| echo -e "${BLUE}═══════════════════════════════════════════════════════════${RESET}\n" | |
| exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment