Skip to main content

A tool to chain multiple WireGuard VPNs and rotate them dynamically via API

Project description

VPN-Chainer ๐Ÿ›ก๏ธ

A powerful WireGuard VPN chaining tool with dynamic routing, automated service control, and API support.

VPN-Chainer WireGuard Python

๐Ÿ”น Overview

VPN-Chainer allows you to chain multiple WireGuard VPNs together, dynamically reordering routes for improved anonymity and security. It includes auto-installation as a system service, API-based VPN rotation, and a customizable pre/post spin-up/down hook system.

Now, you can optionally test VPN speeds and select the fastest VPNs using --fastest.


โšก Features

โœ… Multi-Hop VPN Chaining โ€“ Connect through multiple WireGuard VPNs in random order.
โœ… Speed-Tested VPN Selection โ€“ Use --fastest to pick the top VPNs based on download speed.
โœ… Automatic Routing & Firewall Rules โ€“ Seamless packet forwarding between VPN interfaces.
โœ… Pre/Post Execution Hooks โ€“ Run custom scripts before and after VPN chain events.
โœ… Remote API Support โ€“ Securely rotate VPNs via a web API.
โœ… Auto-Installation as a Systemd Service โ€“ Persistently run VPN-Chainer in the background.


๐Ÿš€ Installation

1๏ธโƒฃ Prerequisites

Ensure you have Python 3 and WireGuard installed:

sudo apt update  
sudo apt install -y python3 python3-pip wireguard  

2๏ธโƒฃ Clone & Install VPN-Chainer

git clone https://github.com/a904guy/VPN-Chainer.git  
cd vpn-chainer  
sudo python3 setup.py install

๐Ÿ› ๏ธ Usage

๐Ÿ”น Basic Usage

sudo vpn-chainer <number_of_vpns>  

For example, to create a 3-hop VPN chain:

sudo vpn-chainer 3  

๐Ÿ”น Use Speed Testing to Select Fastest VPNs

To test all VPNs first and pick the top N fastest VPNs, use --fastest:

sudo vpn-chainer 3 --fastest  

๐Ÿš€ This will:

  • Test all available VPNs in /etc/wireguard/
  • Select the top 3 fastest VPNs
  • Use them in the VPN chain

๐Ÿ”น Install as a Systemd Service

Automatically install and enable the VPN-Chainer service:

sudo vpn-chainer 3 --auto-install  

Once installed, it will start automatically on boot.

To stop or restart the service:

sudo systemctl stop vpn-chainer  
sudo systemctl restart vpn-chainer  

To view logs:

sudo journalctl -u vpn-chainer -f  

๐Ÿ”— API Usage

Rotate VPN Remotely

VPN-Chainer provides an API to trigger VPN rotations. The API key is displayed on startup:

[INFO] VPN-Chainer API running at:  
๐Ÿ”— http://127.0.0.1:5000/rotate_vpn?key=6a1f-45e9...  

To rotate VPNs:

curl -X GET "http://127.0.0.1:5000/rotate_vpn?key=YOUR_API_KEY"  

This will:

  • Tear down the current VPN chain.
  • Randomly select new VPN configs (or use fastest if started with --fastest).
  • Reestablish routing and firewall rules.

โš™๏ธ Hook System (Pre/Post Execution Scripts)

VPN-Chainer allows you to run scripts before and after VPN activation/deactivation.

๐Ÿ”น Hook Script Locations

Scripts should be placed in:

/etc/vpn-chainer/hooks/  
Hook Script Name Triggered When
pre-spin-up.sh Before the VPN chain starts
post-spin-up.sh After the VPN chain is established
pre-spin-down.sh Before VPNs are torn down
post-spin-down.sh After all VPNs have shut down

๐Ÿ”น Example Hook: Restart Tor After VPN Starts

Edit /etc/vpn-chainer/hooks/post-spin-up.sh:

# !/bin/bash  

echo "[HOOK] Restarting Tor for anonymity..."  
systemctl restart tor  

Then enable the hook:

chmod +x /etc/vpn-chainer/hooks/post-spin-up.sh  

๐Ÿ“‚ Configuration Files

VPN-Chainer automatically selects random WireGuard config files from:
/etc/wireguard/*.conf

Ensure that at least the number of VPN configs requested exists. Additionally the Address line is required.

Example VPN config:

[Interface]  
PrivateKey = <YOUR_PRIVATE_KEY>  
Address = 10.13.36.109/24  
DNS = 10.8.0.1  

[Peer]  
PublicKey = <PEER_PUBLIC_KEY>  
Endpoint = 10.10.10.24:51820  
AllowedIPs = 0.0.0.0/0  
PersistentKeepalive = 25  

โ“ Troubleshooting

๐Ÿ”ธ VPN Doesn't Start

  • Check that you have WireGuard installed:
which wg  

If missing, install it:

sudo apt install wireguard  
  • Ensure you have enough VPN config files in /etc/wireguard/.

๐Ÿ”ธ Systemd Service Not Running

  • Check status:
sudo systemctl status vpn-chainer  
  • Restart it:
sudo systemctl restart vpn-chainer  

๐Ÿ”ธ API Not Responding

  • Ensure VPN-Chainer is running:
sudo systemctl status vpn-chainer  
  • Check firewall rules (port 5000 must be open):
sudo ufw allow 5000/tcp  

๐Ÿ“œ Roadmap

โœ”๏ธ Multi-Hop Randomization
โœ”๏ธ Pre/Post Execution Hooks
โœ”๏ธ Auto-Install as a Systemd Service
โœ”๏ธ Speed-Tested VPN Selection (--fastest) (Added in v1.1)
๐Ÿ”œ Web Dashboard for Control & Logs
๐Ÿ”œ VPN Failover Detection โ“โ“
๐Ÿ”œ Split-Tunneling (Selective Routing) โ“โ“
๐Ÿ”œ Submit Your Ideas Via Issues


๐Ÿค Contributing

Want to improve VPN-Chainer? Contributions are welcome! Fork the repository and submit a PR.

  1. Fork & Clone
    git clone https://github.com/a904guy/VPN-Chainer.git cd vpn-chainer

  2. Make Changes & Test
    sudo python3 vpn-chainer.py 3

  3. Submit a Pull Request


๐Ÿ“œ License

This project is licensed under the MIT License.


๐Ÿ‘จโ€๐Ÿ’ป Author

๐Ÿ’ก Created by Andy Hawkins
๐ŸŒ GitHub: a904guy GitHub Profile


๐Ÿš€ VPN-Chainer is your ultimate tool for anonymous, multi-hop VPN tunneling! ๐Ÿ”ฅ ๐Ÿ’ฌ Have questions or feature requests? Open an Issue on GitHub! ๐Ÿ˜Ž

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vpn_chainer-1.2.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vpn_chainer-1.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file vpn_chainer-1.2.0.tar.gz.

File metadata

  • Download URL: vpn_chainer-1.2.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for vpn_chainer-1.2.0.tar.gz
Algorithm Hash digest
SHA256 9e0ff51a75fd15cac3009fefb77a1975eb48c9d683b108a65a995c49cf61d5ce
MD5 691cb269b6a7dd01deccab22747f816f
BLAKE2b-256 3f1aa25233b120063bcecae57a6c92bd7eee3d87c9a6356ba3cc8f34153b82b2

See more details on using hashes here.

File details

Details for the file vpn_chainer-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: vpn_chainer-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for vpn_chainer-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30f5a7cb8c16bba8049fa2c2723f40ee687b26ad5d9398cf2fb6a00972c02111
MD5 5d02029800f8d2da34d8c699ece5e0ef
BLAKE2b-256 829db27b1b43b4265af395ab0614ddc45384e21528c61dc01460ff62cc72a20f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page