Skip to content

Instantly share code, notes, and snippets.

@mskian
Created February 25, 2019 09:39
Show Gist options
  • Save mskian/2b26003d97b4a2d7b95b986661be10dd to your computer and use it in GitHub Desktop.
Save mskian/2b26003d97b4a2d7b95b986661be10dd to your computer and use it in GitHub Desktop.
Python to Check the Connection Status of a NordVPN
import sys
import json
import time
import requests
from halo import Halo
spinner = Halo(text='Loading', color='green', spinner='hamburger')
try:
spinner.start()
time.sleep(2)
spinner.text = 'Verifying the VPN Connection'
r = requests.get('https://api.nordvpn.com/vpn/check/full')
DATA = json.loads(r.content.decode())
time.sleep(2)
spinner.stop()
except json.decoder.JSONDecodeError as e:
spinner.start()
time.sleep(2)
spinner.color = 'red'
spinner.text = 'JSON Decode Error'
time.sleep(2)
spinner.stop()
print("OOPS!! JSON Decode Error")
except requests.ConnectionError as e:
spinner.start()
time.sleep(2)
spinner.color = 'red'
spinner.text = 'URL Error - Empty URL or Wrong URL'
time.sleep(2)
spinner.stop()
print("OOPS!! Connection Error")
except requests.Timeout as e:
print("OOPS!! Timeout Error")
except requests.RequestException as e:
spinner.start()
time.sleep(2)
spinner.color = 'red'
spinner.text = 'Wrong URL or Empty Field'
time.sleep(2)
spinner.stop()
print("OOPS!! General Error")
except (KeyboardInterrupt, SystemExit):
spinner.stop()
print("Ok ok, quitting")
sys.exit(1)
else:
if DATA["status"] == "Unprotected":
print("Unprotected - NordVPN is Not Connected")
else:
print("IP:", DATA['ip'], "\nVPN Status:", DATA['status'], "\nConnected Country:", DATA['country'], "\nISP:", DATA['isp'])
@mskian
Copy link
Author

mskian commented Feb 25, 2019

Requirements

  • Python3

PIP Modules

  • Terminal Spinner
pip install halo
  • Requests
pip install requests

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