Dhi13man / auto_vpn_connect

A Python script that allows users to automatically connect to VPNs with minimal effort.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

auto_vpn_connect

License Contributors GitHub forks GitHub Repo stars Last Commit Build, Format, Test

Language "Buy Me A Coffee"

A Python script that allows users to automatically connect to VPNs with minimal effort. As of now, only Pritunl VPN Client is supported.

Usage

Steps

  1. Go to the releases page and download the latest release binary, or clone this repository.

  2. 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": {
                "cli_path": "/Applications/Pritunl.app/Contents/Resources/pritunl-client"
            }
        },
        "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>"
            }
        ]
    }
  3. After ensuring that the vpn_data.json is proper, run the downloaded binary, or the script with python3 -m . from the root of the repository along with the proper switches.

Finding the VPN Data

Pritunl VPN Client

  1. vpn_list.{item}.vpn_id: In the Pritunl VPN Client, go to the Settings of the respective VPN Profile to find the VPN ID or use the pritunl-client CLI command list to get the list of VPNs and their IDs.

    /Applications/Pritunl.app/Contents/Resources/pritunl-client list
  2. 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.

  3. 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.

  4. 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.

  5. vpn_list.{item}.vpn_type: This is the type of VPN that you are connecting to. For Pritunl VPN client, this will be PRITUNL.

  6. 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:

  1. Pritunl VPN Client CLI
  2. Pritunl VPN Client UI
Pritunl VPN Client Screenshots
VPN ID in Pritunl Client UI VPN ID in Pritunl Client CLI
VPN ID in Pritunl Client UI VPN ID in Pritunl Client CLI
Add VPN in Pritunl Client UI Add VPN in Pritunl Client CLI
Add VPN in Pritunl Client UI Add VPN using Pritunl Client CLI

User Switches

  1. 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 VPNs
    • d: Disconnects from the VPNs
    • w: Runs the script in watch mode, which will automatically re-attempt connecting to the VPNs when they disconnect.
  2. VPN Data Path Switch -p / --path (optional): The VPN Data Path Switch allows the user to specify the absolute path to the vpn_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>
  3. 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

Examples

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

Development

Setup

  1. Clone the repository
  2. Install the Development Dependencies with pip3 install -r requirements.txt
  3. Run python3 -m . from the root of the repository

Dependencies

Development Dependencies

External Dependencies

  • Pritunl VPN Client: Used for connecting, disconnecting to VPNs (only supported VPN Client type as of now)

Build

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.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Screenshots

Connect using Repository with VPN Data Config Path Provided
Connect using Repository, with VPN Data Config Path Provided
Disconnect with CLI in Verbose Mode
Disconnect using CLI, in Verbose Mode

About

A Python script that allows users to automatically connect to VPNs with minimal effort.

License:MIT License


Languages

Language:Python 100.0%