Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
Add tier to -random. Update readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-born committed Apr 10, 2019
1 parent 93a76be commit 5b6eb33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions protonvpn-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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' \
Expand All @@ -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 <<END
import json, random
json_parsed_response = json.loads("""$response_output""")
output = []
for _ in json_parsed_response["LogicalServers"]:
if (_["Tier"] <= int("""$tier""")):
if (_["Tier"] <= int("""$tier""") and _["Tier"] >= int("""$min_tier""")):
output.append(_)
print(random.choice(output)["ID"])
END`
Expand Down Expand Up @@ -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
;;
Expand Down

0 comments on commit 5b6eb33

Please sign in to comment.