Skip to content

Instantly share code, notes, and snippets.

@Dreyer
Last active July 21, 2025 15:28
Show Gist options
  • Save Dreyer/161b920f0d8300ed3bc750ae2f80c339 to your computer and use it in GitHub Desktop.
Save Dreyer/161b920f0d8300ed3bc750ae2f80c339 to your computer and use it in GitHub Desktop.
Check the status of a NordVPN connection from your shell.
#!/bin/bash
URL='https://web-api.nordvpn.com/v1/ips/info'
JSON=$(curl -s $URL)
printf "\n"
#echo $JSON | python -m json.tool
echo $JSON | python -c 'import sys, json; data = json.load(sys.stdin); print("IP: %s (%s)\nStatus: %s" % (data["ip"], data["isp"], "\033[32mProtected" if data["protected"] is True else "\033[31mUnprotected"));'
printf "\n"
@zerealfox
Copy link

I just added an exit code that can be tested upon script end (in Unix it's $? )

#!/bin/bash

URL='https://web-api.nordvpn.com/v1/ips/info'
JSON=$(curl -s $URL)

printf "\n"
#echo $JSON | python -m json.tool
echo $JSON | python -c 'import sys, json; exitCode=0; data = json.load(sys.stdin); print("IP: %s (%s)\nStatus: %s" % (data["ip"], data["isp"], "\033[32mProtected\n" if data["protected"] is True else "\033[31mUnprotected\n")); exitCode= 1 if data["protected"] is False else 0; sys.exit(exitCode);'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment