# nordvpn_get_ip # -------------- # Obtiene la IP publica actual para verificar que el tunel VPN funciona. # Usa multiples servicios como fallback. # # USO (sourced): # source nordvpn_get_ip.sh # nordvpn_get_ip nordvpn_get_ip() { local ip="" local source="" # Intentar multiples servicios for svc in "https://api.ipify.org" "https://ifconfig.me" "https://icanhazip.com"; do ip=$(curl -s --max-time 5 "$svc" 2>/dev/null) if echo "$ip" | grep -qP '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'; then source="$svc" break fi ip="" done if [ -z "$ip" ]; then echo '{"ok":false,"error":"no se pudo obtener IP publica"}' >&2 return 1 fi # Si nordvpn esta disponible, incluir info de conexion local connected="false" local vpn_server="" if command -v nordvpn &>/dev/null; then local status_output status_output=$(nordvpn status 2>/dev/null) if echo "$status_output" | grep -qi "connected"; then connected="true" vpn_server=$(echo "$status_output" | grep -iP "hostname|server" | head -1 | sed 's/.*: *//') fi fi echo "{\"ok\":true,\"ip\":\"$ip\",\"vpn_connected\":$connected,\"vpn_server\":\"$vpn_server\",\"source\":\"$source\"}" }