Created
February 25, 2019 09:39
-
-
Save mskian/2b26003d97b4a2d7b95b986661be10dd to your computer and use it in GitHub Desktop.
Python to Check the Connection Status of a NordVPN
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
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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
PIP Modules