Skip to content

Commit 329e3df

Browse files
authored
Nord 3.17.4 update
function server_load - have not found a way to query the api directly by hostname, but "server id" will work. As a workaround will search the local "nordserversfile" to find the server id, and use that to query the api for the current server load. See customization option "nordserversfile" to create the file. #6
1 parent 7414d8e commit 329e3df

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

nordlist.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# shellcheck disable=SC2034,SC2129,SC2154
33
# unused color variables, individual redirects, var assigned
44
#
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
77
#
88
# This script works with the NordVPN Linux CLI. I started
99
# writing it to save some keystrokes on my Home Theatre PC.
@@ -162,10 +162,9 @@ exitkillswitch="n"
162162
# Ping the connected server when the script exits. "y" or "n"
163163
exitping="n"
164164
#
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"
169168
#
170169
# Show your external IP address when the script exits. "y" or "n"
171170
# Requires 'curl'. Connects to ipinfo.io.
@@ -274,7 +273,7 @@ nordvirtual=( "Algeria" "Andorra" "Armenia" "Azerbaijan" "Bahamas" "Bangladesh"
274273
# Main Menu
275274
# ==========
276275
#
277-
# The Main Menu starts on line 4284 (function main_menu).
276+
# The Main Menu starts on line 4304 (function main_menu).
278277
# Configure the first ten main menu items to suit your needs.
279278
#
280279
# Enjoy!
@@ -3214,8 +3213,29 @@ function server_load {
32143213
return
32153214
fi
32163215
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
32183217
# 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+
#
32193239
if [[ -z $sload ]]; then
32203240
echo "Request timed out."
32213241
elif (( sload <= 30 )); then

0 commit comments

Comments
 (0)