This is a Python script that allows users to automatically connect to VPNs with minimal effort. VPNs supported as of now:
- Pritunl VPN Client
- Palo Alto Global Protect
- For a more lightweight script that only solves the Global Protect VPN use case, check out my global_protect_controller project.
-
Go to the releases page and download the latest release binary, or clone this repository.
-
In the same directory as the script, or inside the root of the repository, create (or edit) a file called
vpn_data.json
and fill it with the following information (replace the values with your own):{ "config": { "PRITUNL": { "vpn_type": "PRITUNL", "cli_path": "/Applications/Pritunl.app/Contents/Resources/pritunl-client" }, "GLOBAL_PROTECT": { "vpn_type": "GLOBAL_PROTECT", "service_load_command": "launchctl load /Library/LaunchAgents/com.paloaltonetworks.gp.pangpa.plist", "service_unload_command": "launchctl unload /Library/LaunchAgents/com.paloaltonetworks.gp.pangpa.plist", "process_kill_command": "pkill -9 -f GlobalProtect" } }, "vpn_list": [ { "vpn_id": "<vpn_id_1>", "vpn_type": "PRITUNL", "pin": "<vpn_pin_1>" }, { "vpn_id": "<vpn_id_2>", "vpn_type": "PRITUNL", "pin": "<vpn_pin_2>", "totp_url": "<totp_url>" }, { "vpn_id": "<vpn_id_3>", "vpn_type": "PRITUNL", "pin": "<vpn_pin_3>", "token": "<vpn_token>" }, { "vpn_id": "GlobalProtect", "vpn_type": "GLOBAL_PROTECT" } ] }
-
After ensuring that the
vpn_data.json
is proper, run the downloaded binary, or the script withpython3 -m .
from the root of the repository along with the proper switches.
-
vpn_list.{item}.vpn_id
: In the Pritunl VPN Client, go to theSettings
of the respective VPN Profile to find the VPN ID or use thepritunl-client
CLI commandlist
to get the list of VPNs and their IDs./Applications/Pritunl.app/Contents/Resources/pritunl-client list
-
vpn_list.{item}.pin
: This is the PIN that you use to connect to the VPN. If there is no PIN, leave the field blank. -
vpn_list.{item}.totp_url
: This is the URL in the payload of the TOTP QR code that you use to connect to the VPN. If there is no TOTP QR code, leave the field blank. -
vpn_list.{item}.token
: This is the token that you use to connect to the VPN. If there is no token, leave the field blank. -
vpn_list.{item}.vpn_type
: This is the type of VPN that you are connecting to. For Pritunl VPN client, this will bePRITUNL
. -
config.PRITUNL.cli_path
: This is the path to the Pritunl VPN Client CLI. If the Pritunl VPN Client is installed in the default location, leave the field blank.
Further resources:
VPN ID in Pritunl Client UI | VPN ID in Pritunl Client CLI |
Add VPN in Pritunl Client UI | Add VPN using Pritunl Client CLI |
Global Protect VPN does not have the hassle of managing multiple connections. You only have to put in a config with a dummy VPN ID as shown in the example above and then sign in with SSO whenever you use the CLI to connect to it. Disconnecting from Global Protect will require no additional input.
-
Action Switch
-a
/--action
(optional): The action switch allows the user to specify the action that the script should perform. If the action switch is not specified, the script will run in interactive mode, which will prompt the user to select an action.cd <path_to_script> ./auto_vpn_connect --action <action>
cd <path_to_repository> python3 -m . -a <action>
Running with action switch will run the script with the specified action. The available actions are:
c
: Connects to the VPNsd
: Disconnects from the VPNsw
: Runs the script in watch mode, which will automatically re-attempt connecting to the VPNs when they disconnect.
-
VPN Data Path Switch
-p
/--path
(optional): The VPN Data Path Switch allows the user to specify the absolute path to thevpn_data.json
file. If the switch is not specified, the script will look for the file in the directory it is run from, or in the root of the repository, if the script is run from the root of the cloned repository.cd <path_to_script> ./auto_vpn_connect -p <path_to_vpn_data.json>
cd <path_to_repository> python3 -m . --path <path_to_vpn_data.json>
-
Verbose Switch
-v
/--verbose
(optional): The verbose switch allows the user to specify whether the script should print verbose output. If the switch is not specified, the script will run in non-verbose mode.cd <path_to_script> ./auto_vpn_connect --verbose true
cd <path_to_repository> python3 -m . -v true
cd <path_to_script>
./auto_vpn_connect --action c --path <path_to_folder>/vpn_data.json --verbose true
cd <path_to_repository>
python3 -m . --action w --path <path_to_folder>/vpn_data.json --verbose false
cd <path_to_script>
./auto_vpn_connect --action d
- Clone the repository
- Install the Development Dependencies with
pip3 install -r requirements.txt
- Run
python3 -m .
from the root of the repository
- Python 3.10+: Used for developing the script
- pyotp: Used for generating OTPs
- Pritunl VPN Client: Used for connecting, disconnecting to VPNs (only supported VPN Client type as of now)
This project uses PyInstaller to build the binary. To build the binary, run the following command from the root of the repository:
pyinstaller --onefile --windowed __main__.py
This will create a dist
folder in the root of the repository, which will contain the binary without any dependencies.
The binary can be run from anywhere following the Usage instructions.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Connect using Repository, with VPN Data Config Path Provided |
Disconnect using CLI, in Verbose Mode |