-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-port.py
42 lines (32 loc) · 1.17 KB
/
check-port.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import os
import subprocess
from dotenv import load_dotenv
import requests
# set up in crontab
# /home/USER/mullvad-port-checker/venv/bin/python3 /home/USER/mullvad-port-checker/check-port.py >> output.log
###############################################
# initialize vars and get the script rolling!
###############################################
# load .env vars which contains my tokens
load_dotenv()
PUSHOVER_USER_TOKEN = os.getenv("PUSHOVER_USER_TOKEN")
PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
PORT = os.getenv("PORT")
result = subprocess.run(
f"/usr/bin/docker exec qbittorrent curl -s https://am.i.mullvad.net/port/{PORT}",
shell=True,
stdout=subprocess.PIPE,
)
mullvad_response = json.loads(result.stdout)
print(mullvad_response)
if mullvad_response["reachable"] == False:
print(f"Mullvad port {PORT} is closed.")
url = "https://api.pushover.net/1/messages.json"
params = {
"token": PUSHOVER_API_TOKEN,
"user": PUSHOVER_USER_TOKEN,
"message": f"Mullvad port {PORT} is closed.",
}
pushover_response = requests.post(url, params=params)
print(f"Response from Pushover: {pushover_response.text}")