Created
April 17, 2026 08:15
-
-
Save eladcandroid/80d36279836d48ba84c5c66f536889b1 to your computer and use it in GitHub Desktop.
Run any geo-blocked CLI tool through ProtonVPN on macOS — auto-connect, run, auto-disconnect
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
| #!/bin/bash | |
| # vpn-run.sh — Connect VPN, run any command, disconnect on exit | |
| # Usage: ./vpn-run.sh <command> [args...] | |
| # | |
| # Examples: | |
| # ./vpn-run.sh freebuff | |
| # ./vpn-run.sh curl https://some-blocked-api.com | |
| # ./vpn-run.sh npm start | |
| VPN_ID=$(scutil --nc list | grep "protonvpn" | grep -oE '[0-9A-F-]{36}' | head -1) | |
| WAS_CONNECTED=false | |
| [[ -z "$VPN_ID" ]] && echo "ProtonVPN not found" && exit 1 | |
| # Disconnect on exit (only if we connected it) | |
| cleanup() { [[ "$WAS_CONNECTED" = false ]] && scutil --nc stop "$VPN_ID" 2>/dev/null && echo "VPN disconnected"; } | |
| trap cleanup EXIT | |
| # Connect | |
| if [[ "$(scutil --nc status "$VPN_ID" | head -1)" = "Connected" ]]; then | |
| WAS_CONNECTED=true | |
| echo "VPN already connected" | |
| else | |
| echo -n "Connecting VPN..." | |
| scutil --nc start "$VPN_ID" | |
| until [[ "$(scutil --nc status "$VPN_ID" | head -1)" = "Connected" ]]; do sleep 1; echo -n "."; done | |
| echo " done ($(curl -s ipinfo.io/country))" | |
| fi | |
| # Run the command | |
| "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment