Author: MD FAYSAL MAHMUD
This Python script automates the process of downloading, configuring, and connecting to free OpenVPN servers provided by VPNBook. It downloads VPN configuration files, extracts them, modifies them to bypass specific IPs and ports (e.g., for RDP and SSH), tests the servers for latency, and connects to the fastest one. The script is designed for educational purposes and should be used responsibly in a legal and authorized environment.
- Automatic Download: Fetches OpenVPN configuration files from VPNBook.
- File Extraction and Modification: Extracts
.ovpn
files and adds custom routes to bypass VPN for specific IPs. An Example IP is Given but you should replace with your own REAL IP (e.g., 77.254.229.234, you should put your real ip there) and ports (3389 for RDP, 22 for SSH). - Firewall Configuration: Configures the system firewall to allow RDP and SSH traffic.
- Latency Testing: Tests each VPN server’s latency by pinging Google’s DNS (8.8.8.8) and selects the fastest one.
- VPN Connection: Connects to the best VPN server using OpenVPN with provided credentials.
- Error Handling: Includes logging for debugging and error tracking.
To run this script on Kali Linux or Ubuntu, you need the following:
- Python 3: Version 3.6 or higher (pre-installed on Kali/Ubuntu).
- OpenVPN: For connecting to VPN servers.
- Unzip: To extract
.zip
files. - UFW: For firewall configuration (optional, but used by the script).
- Ping: For latency testing (part of
iputils-ping
).
requests
: For downloading files.urllib3
: For handling HTTPS requests.zipfile
: For extracting.zip
files (included in Python standard library).subprocess
: For running system commands (included in Python standard library).shutil
: For file operations (included in Python standard library).logging
: For logging (included in Python standard library).glob
: For file pattern matching (included in Python standard library).typing
: For type hints (included in Python standard library).
- Root Privileges: The script uses
sudo
for OpenVPN and UFW commands, so you need administrative access.
Follow these steps to set up the environment on Kali Linux or Ubuntu:
-
Update Your System:
sudo apt update && sudo apt upgrade -y
-
Install Required Software:
sudo apt install -y python3 python3-pip openvpn unzip iputils-ping ufw
-
Install Python Packages:
pip3 install requests urllib3
-
Verify Installation:
- Check Python version:
python3 --version
- Check OpenVPN:
openvpn --version
- Check UFW:
ufw --version
- Check pip:
pip3 --version
- Check Python version:
-
Download the Script:
- Clone this repository or download
OpenVpn.py
:git clone https://github.com/Blindsinner/OpenVPN-Automation-Script.git cd OpenVPN-Automation-Script
- Clone this repository or download
The script automates the entire process of setting up and connecting to a VPNBook OpenVPN server. Follow these steps:
-
Prepare the Script:
- Ensure
OpenVpn.py
is in your working directory. - Make it executable:
chmod +x OpenVpn.py
- Ensure
-
Update VPN Credentials:
- The script contains the following default VPNBook credentials:
VPN_USERNAME = "vpnbook" VPN_PASSWORD = "cf32e5w"
- Important: VPNBook changes these credentials periodically (often weekly or monthly). You must update these lines in
OpenVpn.py
with the latest username and password from vpnbook.com. - To update:
- Open
OpenVpn.py
in a text editor (e.g.,nano OpenVpn.py
). - Visit vpnbook.com and find the current OpenVPN username and password.
- Replace the
VPN_USERNAME
andVPN_PASSWORD
values in the script with the new credentials. - Save and close the file.
- Open
- The script contains the following default VPNBook credentials:
-
Run the Script:
sudo python3 OpenVpn.py
- Why
sudo
? The script needs root privileges for OpenVPN and UFW commands. - You’ll be prompted for your system password.
- Why
-
What the Script Does:
- Cleans up old VPN files in
/tmp/vpn_configs
. - Downloads
.zip
files containing.ovpn
configurations from VPNBook. - Extracts and modifies
.ovpn
files to bypass VPN for:- IP
77.254.229.234
. (You should use your own real ip) - Ports 3389 (RDP) and 22 (SSH).
- IP
- Configures the firewall to allow RDP and SSH traffic.
- Tests each VPN server’s latency by pinging
8.8.8.8
. - Connects to the fastest VPN server using OpenVPN.
- Cleans up old VPN files in
-
Monitor Output:
- The script logs progress (e.g., downloading, extracting, connecting).
- Example output:
2025-06-08 21:24:35,123 - INFO - Old VPN files removed. 2025-06-08 21:24:36,456 - INFO - Downloading: https://www.vpnbook.com/free-openvpn-account/vpnbook-openvpn-ca149.zip 2025-06-08 21:24:38,789 - INFO - Fastest working VPN: /tmp/vpn_configs/vpnbook-openvpn-ca149/vpnbook-ca149-tcp443.ovpn
- If successful, OpenVPN will connect, and you’ll see its logs.
-
Stop the VPN:
- To disconnect, press
Ctrl+C
in the terminal running the script. - Clean up manually if needed:
sudo rm -rf /tmp/vpn_configs
- To disconnect, press
sudo python3 OpenVpn.py
- The script downloads VPN configurations, tests them, and connects to the fastest server.
- Check your IP to confirm the VPN is working:
curl ifconfig.me
- If the IP differs from your real IP, the VPN is active.
- Error: “No .zip files downloaded”:
- Check your internet connection.
- Ensure VPNBook links in
ZIP_LINKS
are valid (visit vpnbook.com to confirm).
- Error: “Failed to connect to VPN”:
- Verify OpenVPN is installed (
openvpn --version
). - Ensure the credentials in
OpenVpn.py
(VPN_USERNAME
andVPN_PASSWORD
) match the latest ones from vpnbook.com. - Check that
auth.txt
was created in/tmp/vpn_configs
.
- Verify OpenVPN is installed (
- Error: “Permission denied”:
- Run the script with
sudo
.
- Run the script with
- Error: “Ping timeout”:
- Some VPN servers may be down. Try running the script again.
- Logs: Check
/tmp/vpn_configs
for files and review terminal logs for errors.
- Credential Updates: The script’s default VPN credentials (
VPN_USERNAME = "vpnbook"
,VPN_PASSWORD = "cf32e5w"
) are placeholders and will not work if outdated. VPNBook updates these credentials regularly (often weekly or monthly). Before running the script, always visit vpnbook.com to get the latest username and password, and update theVPN_USERNAME
andVPN_PASSWORD
lines inOpenVpn.py
. - Legal Use: Only use this script for educational purposes or with explicit permission. Unauthorized VPN usage may violate laws or terms of service.
- Security: The script disables HTTPS warnings (
urllib3.disable_warnings
) for simplicity. In production, verify SSL certificates. - Firewall: The script enables UFW rules for ports 3389 and 22. To reset UFW:
sudo ufw reset
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make changes and commit (
git commit -m "Add your feature"
). - Push to your branch (
git push origin feature/your-feature
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.
- VPNBook: For providing free OpenVPN configurations.
- Python Community: For libraries like
requests
andurllib3
.
For questions or issues, contact MD FAYSAL MAHMUD via GitHub Issues.