Skip to content

Instantly share code, notes, and snippets.

@j3lte
Forked from Dreyer/nordvpn.sh
Created February 8, 2023 12:16
Show Gist options
  • Save j3lte/97b4e6784d2463e2b073e3a61b74baf4 to your computer and use it in GitHub Desktop.
Save j3lte/97b4e6784d2463e2b073e3a61b74baf4 to your computer and use it in GitHub Desktop.
Check the status of a NordVPN connection from your shell.
#!/bin/bash
URL='https://nordvpn.com/wp-admin/admin-ajax.php?action=get_user_info_data'
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["status"] is True else "\033[31mUnprotected");'
printf "\n"
#
# Automatically reconnect when disconnected from the VPN.
#
# You don't need this if you're using the NordVPN application.
# This is a utility for using native VPN connection settings on MacOS.
#
on idle
tell application "System Events"
tell current location of network preferences
set myConnection to the service "WorkVPN"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
return 120
end tell
end idle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment