diff --git a/README.md b/README.md index 4a167b3..0a00d16 100644 --- a/README.md +++ b/README.md @@ -41,29 +41,29 @@ $ wget "https://github.com/ProtonVPN/protonvpn-cli/raw/master/protonvpn-cli.sh" # Usage # -| **Command** | **Description** | -| :-------------------------------------------- | :------------------------------------------------------------- | -| `protonvpn-cli --init` | Initialize ProtonVPN profile on the machine. | -| `protonvpn-cli -c, --connect` | Select and connect to a ProtonVPN server. | -| `protonvpn-cli -c [server-name] [protocol]` | Connect to a ProtonVPN server by name. | -| `protonvpn-cli -m, --menu` | Select and connect to a ProtonVPN server from a menu. | -| `protonvpn-cli -r, --random-connect` | Connect to a random ProtonVPN server. | -| `protonvpn-cli -l, --last-connect` | Connect to the previously used ProtonVPN server. | -| `protonvpn-cli -f, --fastest-connect` | Connect to the fastest available ProtonVPN server. | -| `protonvpn-cli -p2p, --p2p-connect` | Connect to the fastest available P2P ProtonVPN server. | -| `protonvpn-cli -tor, --tor-connect` | Connect to the fastest available ProtonVPN TOR server. | -| `protonvpn-cli -sc, --secure-core-connect` | Connect to the fastest available ProtonVPN SecureCore server. | -| `protonvpn-cli -cc, --country-connect` | Select and connect to a ProtonVPN server by country. | -| `protonvpn-cli -cc [country-name] [protocol]` | Connect to the fastest available server in a specific country. | -| `protonvpn-cli -d, --disconnect` | Disconnect the current session. | -| `protonvpn-cli --reconnect` | Reconnect to the current ProtonVPN server. | -| `protonvpn-cli --ip` | Print the current public IP address. | -| `protonvpn-cli --status` | Print connection status. | -| `protonvpn-cli --update` | Update protonvpn-cli. | -| `protonvpn-cli --install` | Install protonvpn-cli. | -| `protonvpn-cli --uninstall` | Uninstall protonvpn-cli. | -| `protonvpn-cli --version` | Display version. | -| `protonvpn-cli --help` | Show help message. | +| **Command** | **Description** | +| :--------------------------------------------------- | :------------------------------------------------------------- | +| `protonvpn-cli --init` | Initialize ProtonVPN profile on the machine. | +| `protonvpn-cli -c, --connect` | Select and connect to a ProtonVPN server. | +| `protonvpn-cli -c [server-name] [protocol] [tier]` | Connect to a ProtonVPN server by name. | +| `protonvpn-cli -m, --menu` | Select and connect to a ProtonVPN server from a menu. | +| `protonvpn-cli -r, --random-connect [tier]` | Connect to a random ProtonVPN server. | +| `protonvpn-cli -l, --last-connect` | Connect to the previously used ProtonVPN server. | +| `protonvpn-cli -f, --fastest-connect [tier]` | Connect to the fastest available ProtonVPN server. | +| `protonvpn-cli -p2p, --p2p-connect [tier]` | Connect to the fastest available P2P ProtonVPN server. | +| `protonvpn-cli -tor, --tor-connect [tier]` | Connect to the fastest available ProtonVPN TOR server. | +| `protonvpn-cli -sc, --secure-core-connect [tier]` | Connect to the fastest available ProtonVPN SecureCore server. | +| `protonvpn-cli -cc, --country-connect [tier]` | Select and connect to a ProtonVPN server by country. | +| `protonvpn-cli -cc [country-name] [protocol] [tier]` | Connect to the fastest available server in a specific country. | +| `protonvpn-cli -d, --disconnect` | Disconnect the current session. | +| `protonvpn-cli --reconnect` | Reconnect to the current ProtonVPN server. | +| `protonvpn-cli --ip` | Print the current public IP address. | +| `protonvpn-cli --status` | Print connection status. | +| `protonvpn-cli --update` | Update protonvpn-cli. | +| `protonvpn-cli --install` | Install protonvpn-cli. | +| `protonvpn-cli --uninstall` | Uninstall protonvpn-cli. | +| `protonvpn-cli --version` | Display version. | +| `protonvpn-cli --help` | Show help message. | protonvpn-cli can also be used by typing `pvpn`, once installed. diff --git a/protonvpn-cli.sh b/protonvpn-cli.sh index 69e387c..e01ccd2 100755 --- a/protonvpn-cli.sh +++ b/protonvpn-cli.sh @@ -838,7 +838,7 @@ function connect_to_random_vpn() { check_if_internet_is_working_normally echo "Fetching ProtonVPN servers..." - config_id=$(get_random_vpn_connection_id) + config_id=$(get_random_vpn_connection_id "$1") available_protocols=("tcp" "udp") selected_protocol=${available_protocols[$RANDOM % ${#available_protocols[@]}]} openvpn_connect "$config_id" "$selected_protocol" @@ -1433,6 +1433,7 @@ END` } function get_random_vpn_connection_id() { + min_tier=${1:-0} response_output=$(wget --header 'x-pm-appversion: Other' \ --header 'x-pm-apiversion: 3' \ --header 'Accept: application/vnd.protonmail.v1+json' \ @@ -1444,12 +1445,15 @@ function get_random_vpn_connection_id() { fi tier=$(< "$(get_protonvpn_cli_home)/protonvpn_tier") + if [[ $min_tier -gt $tier ]]; then + min_tier=$tier + fi output=`$python <= int("""$min_tier""")): output.append(_) print(random.choice(output)["ID"]) END` @@ -1555,7 +1559,7 @@ case $user_input in ;; "-reconnect"|"--reconnect") reconnect_to_current_vpn ;; - "-r"|"--r"|"-random"|"--random"|"-random-connect"|"--random-connect") connect_to_random_vpn + "-r"|"--r"|"-random"|"--random"|"-random-connect"|"--random-connect") connect_to_random_vpn "$2" ;; "-l"|"--l"|"-last-connect"|"--last-connect") connect_to_previous_vpn ;;