Last active
April 7, 2025 22:45
-
-
Save electblake/c173af23b05bf0b029600836224f4006 to your computer and use it in GitHub Desktop.
list and search socks servers using nordvpn api
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 | |
# Fetch data from API and store it in a variable | |
data=$(curl --silent --globoff "https://api.nordvpn.com/v1/servers?filters[servers_technologies][identifier]=socks&limit=0" | \ | |
jq '[.[] | { | |
name: .name, | |
created_at: .created_at, | |
hostname: .hostname, | |
ip: .station, | |
load: .load, | |
status: .status, | |
location: (.locations[0].country.city.name + ", " + .locations[0].country.name), | |
country: .locations[0].country.name | |
}]') | |
# Check if data is not empty | |
if [ -z "$data" ]; then | |
echo "Failed to fetch data or data is empty." | |
exit 1 | |
fi | |
# Ask for sorting preference | |
echo "How would you like to sort the data? Options: load, name, status" | |
read sort_option | |
# Ensure valid sort option is chosen | |
if [[ "$sort_option" != "load" && "$sort_option" != "name" && "$sort_option" != "status" ]]; then | |
echo "Invalid sort option selected." | |
exit 1 | |
fi | |
# Ask for country filter preference | |
echo "Do you want to filter by country? Enter country name or 'no' to skip:" | |
read country_filter | |
# Apply sorting and optional filtering | |
if [ "$country_filter" = "no" ]; then | |
jq_command="sort_by(.$sort_option)" | |
else | |
jq_command="map(select(.country == \"$country_filter\")) | sort_by(.$sort_option)" | |
fi | |
# Execute jq command on the variable and display the result | |
echo "$data" | jq "$jq_command" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment