|
2 | 2 | # shellcheck disable=SC2034,SC2129,SC2154
|
3 | 3 | # unused color variables, individual redirects, var assigned
|
4 | 4 | #
|
5 |
| -# Tested with NordVPN Version 3.17.3 on Linux Mint 21.3 |
6 |
| -# March 28, 2024 |
| 5 | +# Tested with NordVPN Version 3.17.4 on Linux Mint 21.3 |
| 6 | +# April 5, 2024 |
7 | 7 | #
|
8 | 8 | # This script works with the NordVPN Linux CLI. I started
|
9 | 9 | # writing it to save some keystrokes on my Home Theatre PC.
|
@@ -162,10 +162,9 @@ exitkillswitch="n"
|
162 | 162 | # Ping the connected server when the script exits. "y" or "n"
|
163 | 163 | exitping="n"
|
164 | 164 | #
|
165 |
| -# Query the server load when the script exits. "y" or "n" |
166 |
| -# Requires 'curl' and 'jq'. |
167 |
| -# currently broken. see https://github.com/ph202107/nordlist/issues/6 |
168 |
| -# exitload="n" |
| 165 | +# Query the current server load when the script exits. "y" or "n" |
| 166 | +# Requires 'curl' 'jq' and the local 'nordserversfile' mentioned above. |
| 167 | +exitload="n" |
169 | 168 | #
|
170 | 169 | # Show your external IP address when the script exits. "y" or "n"
|
171 | 170 | # Requires 'curl'. Connects to ipinfo.io.
|
@@ -274,7 +273,7 @@ nordvirtual=( "Algeria" "Andorra" "Armenia" "Azerbaijan" "Bahamas" "Bangladesh"
|
274 | 273 | # Main Menu
|
275 | 274 | # ==========
|
276 | 275 | #
|
277 |
| -# The Main Menu starts on line 4284 (function main_menu). |
| 276 | +# The Main Menu starts on line 4304 (function main_menu). |
278 | 277 | # Configure the first ten main menu items to suit your needs.
|
279 | 278 | #
|
280 | 279 | # Enjoy!
|
@@ -3214,8 +3213,29 @@ function server_load {
|
3214 | 3213 | return
|
3215 | 3214 | fi
|
3216 | 3215 | echo -ne "$nordhost load = "
|
3217 |
| - # this works but it will download 20MB every time and possible api server timeouts |
| 3216 | + # this will also work but it will download 20MB every time and possible api server timeouts |
3218 | 3217 | # sload=$( timeout 10 curl --silent "https://api.nordvpn.com/v1/servers?limit=999999" | jq --arg host "$nordhost" '.[] | select(.hostname == $host) | .load' )
|
| 3218 | + # |
| 3219 | + # |
| 3220 | + # workaround. https://github.com/ph202107/nordlist/issues/6 |
| 3221 | + if [[ -f "$nordserversfile" ]]; then |
| 3222 | + # have not found a way to query the api directly by "hostname", but "id" works |
| 3223 | + # find the "id" of the current server from the local .json |
| 3224 | + serverid=$( jq --arg host "$nordhost" '.[] | select(.hostname == $host) | .id' "$nordserversfile" ) |
| 3225 | + if [[ -n "$serverid" ]]; then |
| 3226 | + # query the api by the server id. this method downloads about 3KB instead of 20MB |
| 3227 | + sload=$( timeout 10 curl --silent "https://api.nordvpn.com/v1/servers?limit=1&filters\[servers.id\]=$serverid" | jq '.[].load' ) |
| 3228 | + else |
| 3229 | + # servers may be added or removed |
| 3230 | + echo -e "${WColor}No id found for '$nordhost'${Color_Off}" |
| 3231 | + echo "Try updating $nordserversfile" |
| 3232 | + echo "(Tools - NordVPN API - All VPN Servers)" |
| 3233 | + fi |
| 3234 | + else |
| 3235 | + echo -e "${WColor}$nordserversfile not found${Color_Off}" |
| 3236 | + echo "Create the file at: Tools - NordVPN API - All VPN Servers" |
| 3237 | + fi |
| 3238 | + # |
3219 | 3239 | if [[ -z $sload ]]; then
|
3220 | 3240 | echo "Request timed out."
|
3221 | 3241 | elif (( sload <= 30 )); then
|
|
0 commit comments