Added Script

This commit is contained in:
Phil 2024-05-06 15:28:46 +01:00
parent 81ac1d5924
commit eb4c4159ff

66
run_check.sh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
# Mullvad_VPN_Check
# A script that checks for a Mullvad VPN connection and if there isn't one, will send and alert
# Set Discord webhook
WEBHOOK_URL="DISCORD_WEBHOOK_URL"
# Function to run alert
run_alert() {
curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <<EOF
{
"content": null,
"embeds": [
{
"title": "VPN Connectivity - WARNING",
"description": "\"$(hostname)\" is not going through a Mullvad VPN connection",
"color": 5814783,
"fields": [
{
"name": "Date and Time of Test:",
"value": "$(date +'%Y-%m-%d %H:%M:%S')"
},
{
"name": "Current ISP",
"value": "$ORG"
},
{
"name": "Current IP",
"value": "$IP"
}
]
}
],
"attachments": []
}
EOF
}
# Function to check if "mullvad_exit_ip" is false
check_mullvad_exit_ip() {
mullvad_exit_ip="$1"
if [ "$mullvad_exit_ip" = "false" ]; then
run_alert
echo "Alert sent!"
else
echo "VPN connection through Mullvad detected."
exit 1 # Exit with error code to indicate condition not met
fi
}
# Fetch JSON data
json=$(curl -s https://ipv4.am.i.mullvad.net/json)
# Get Reported IP
IP=$(echo "$json" | grep -oE '"ip":\s*"[^"]+"' | grep -oE '[0-9.]+')
# Get Reported ISP
ORG=$(echo "$json" | grep -oP '(?<="organization":")[^"]+')
# Parse JSON and extract "mullvad_exit_ip"
mullvad_exit_ip=$(jq -r '.mullvad_exit_ip' <<< "$json")
# Check if "mullvad_exit_ip" is false
check_mullvad_exit_ip "$mullvad_exit_ip"