98 lines
2.1 KiB
Markdown
98 lines
2.1 KiB
Markdown
|
|
# Mullvad VPN Check
|
||
|
|
|
||
|
|
## Overview
|
||
|
|
|
||
|
|
This Bash script monitors the status of a Mullvad VPN connection. It checks if the system is connected to the Mullvad VPN, logs the connection status, and sends alerts via Discord if the VPN status changes.
|
||
|
|
|
||
|
|
### Features
|
||
|
|
|
||
|
|
* Checks the current VPN connection status using the Mullvad API.
|
||
|
|
* Logs the VPN status to a temporary file.
|
||
|
|
* Sends an alert to a Discord webhook when the VPN connection is lost.
|
||
|
|
* Sends a recovery alert when the VPN connection is restored.
|
||
|
|
|
||
|
|
### Requirements
|
||
|
|
|
||
|
|
- A system running Bash (Linux/macOS)
|
||
|
|
- curl and jq installed
|
||
|
|
- A valid Discord webhook URL
|
||
|
|
|
||
|
|
### Installation
|
||
|
|
|
||
|
|
1) Clone this repository or download the script.
|
||
|
|
|
||
|
|
2_ Ensure you have curl and jq installed:
|
||
|
|
|
||
|
|
```
|
||
|
|
sudo apt install curl jq # For Debian-based systems
|
||
|
|
sudo dnf install curl jq # For Fedora-based systems
|
||
|
|
```
|
||
|
|
|
||
|
|
3) Set up a Discord webhook and replace DISCORD_WEBHOOK_URL in the script with your webhook URL.
|
||
|
|
|
||
|
|
4) Make the script executable:
|
||
|
|
|
||
|
|
```
|
||
|
|
chmod +x mullvad_vpn_check.sh
|
||
|
|
```
|
||
|
|
### Usage
|
||
|
|
|
||
|
|
Run the script manually:
|
||
|
|
|
||
|
|
```
|
||
|
|
./mullvad_vpn_check.sh
|
||
|
|
```
|
||
|
|
|
||
|
|
To automate the script, add it to a cron job:
|
||
|
|
|
||
|
|
```
|
||
|
|
crontab -e
|
||
|
|
```
|
||
|
|
|
||
|
|
Add the following line to check every 5 minutes:
|
||
|
|
|
||
|
|
```
|
||
|
|
*/5 * * * * /path/to/mullvad_vpn_check.sh
|
||
|
|
```
|
||
|
|
|
||
|
|
### How It Works
|
||
|
|
|
||
|
|
The script fetches JSON data from Mullvad's API.
|
||
|
|
|
||
|
|
It extracts the IP and ISP information.
|
||
|
|
|
||
|
|
It checks if the current IP is a Mullvad exit node.
|
||
|
|
|
||
|
|
If the VPN is disconnected, an alert is sent to the configured Discord webhook.
|
||
|
|
|
||
|
|
If the VPN is restored, a recovery alert is sent.
|
||
|
|
|
||
|
|
The connection status is logged to a temporary file for comparison.
|
||
|
|
|
||
|
|
### Example Alerts
|
||
|
|
|
||
|
|
VPN Down Alert:
|
||
|
|
```
|
||
|
|
"[hostname] is not going through a Mullvad VPN connection."
|
||
|
|
```
|
||
|
|
Includes ISP, IP, and timestamp.
|
||
|
|
|
||
|
|
VPN Restored Alert:
|
||
|
|
|
||
|
|
```
|
||
|
|
"[hostname] is now going through a Mullvad VPN connection."
|
||
|
|
```
|
||
|
|
Includes ISP, IP, and timestamp.
|
||
|
|
|
||
|
|
### License
|
||
|
|
|
||
|
|
This project is licensed under the MIT License.
|
||
|
|
|
||
|
|
### Contributions
|
||
|
|
|
||
|
|
Contributions are welcome! Feel free to submit a pull request or open an issue.
|
||
|
|
|
||
|
|
### Disclaimer
|
||
|
|
|
||
|
|
This script is provided as-is without any guarantees. Use at your own risk.
|