This is a very simple Python script that requires very little configuration and has few dependencies.
This script is destined for machines that have an internet kill switch, meaning no internet access unless the Wireguard VPN is up.
The original script linked below is better for pinging IP the Wireguard server IP.
This script was re-written based on a script shared on Reddit. Source is here
- A system that uses Wireguard
- A kill-switch that only allows internet access if the VPN is up
- Copy the script to your desired destination
- Install requests if you don't already have it (
python -m pip install requests
) - Check the script is suitably configured for you.
- Add to your root crontab (
sudo crontab -e
). Root access is used to restart the Wireguard service:*/5 * * * * /usr/bin/python3 /home/USER/wg-watchdog.py
- Use
pythonping
to ping a server instead of checking a website is available. Note that this library does require administrator escalation.