How I Created My Own VPN Server at Home for Free! | Fuzzu VPN Project πŸ”₯

Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡





















Code :


import os

import socket

import threading

import time

import tkinter as tk

from tkinter import messagebox

from ttkbootstrap import Style

from ttkbootstrap.widgets import Button, Combobox, LabelFrame

import subprocess  # Importing subprocess for VPN process control


# Global VPN server and client configurations

HOST = '0.0.0.0'  # Listen on all available interfaces

PORT = 5000        # VPN Server port

DEST_SERVER = 'www.example.com'  # Destination server to route traffic to

DEST_PORT = 80      # Port on the destination server


# Global paths

config_folder = os.path.join(os.getcwd(), "fuzzuvpn_configs")

auth_path = os.path.join(config_folder, "auth.txt")

vpn_process = None

start_time = None

timer_running = False


# VPN server - Forwards data between client and destination server

def handle_client(client_socket):

    try:

        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as dest_socket:

            dest_socket.connect((DEST_SERVER, DEST_PORT))

            

            while True:

                client_data = client_socket.recv(4096)

                if not client_data:

                    break

                dest_socket.send(client_data)


                server_data = dest_socket.recv(4096)

                if not server_data:

                    break


                client_socket.send(server_data)

    

    finally:

        client_socket.close()


# Start the VPN Server

def start_vpn_server():

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:

        server_socket.bind((HOST, PORT))

        server_socket.listen(5)

        print(f"VPN Server listening on {HOST}:{PORT}")


        while True:

            client_socket, client_address = server_socket.accept()

            print(f"Connection from {client_address}")

            threading.Thread(target=handle_client, args=(client_socket,)).start()


# VPN client - Connects to the server and sends data

def start_vpn_client(vpn_server, vpn_port):

    try:

        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as vpn_socket:

            vpn_socket.connect((vpn_server, vpn_port))

            print(f"Connected to VPN server at {vpn_server}:{vpn_port}")

            

            message = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"

            vpn_socket.send(message.encode())

            

            response = vpn_socket.recv(4096)

            print("Response from VPN server:")

            print(response.decode())

    except Exception as e:

        print(f"Error in VPN client: {e}")


# Create the auth file (credentials)

def create_auth_file():

    if not os.path.exists(config_folder):

        os.makedirs(config_folder)

    if not os.path.exists(auth_path):

        with open(auth_path, "w") as f:

            f.write("fuzzu\ndeveloper")  # Replace with actual credentials


# GUI for VPN connection and control

def update_timer():

    global start_time, timer_running

    while timer_running:

        elapsed = int(time.time() - start_time)

        mins, secs = divmod(elapsed, 60)

        timer_label.config(text=f"⏱️ Connected: {mins:02d}:{secs:02d}")

        time.sleep(1)


def connect_vpn():

    global vpn_process, start_time, timer_running


    try:

        # Start VPN Server in a separate thread

        threading.Thread(target=start_vpn_server, daemon=True).start()


        # Start VPN Client directly in the main thread

        threading.Thread(target=start_vpn_client, args=('localhost', PORT), daemon=True).start()


        # Update the Connect button style and text

        dropdown.config(state="disabled")

        connect_btn.config(text="✅ Connected", bootstyle="dark")

        connect_btn.config(state="disabled")  # Disable Connect button after it's clicked


        # Place the Disconnect button below Connect button

        disconnect_btn.place(x=210, y=175)  # Adjust this value for better spacing

        disconnect_btn.config(state="normal", bootstyle="danger")

        disconnect_btn.update()


        if not timer_running:

            start_time = time.time()

            timer_running = True

            threading.Thread(target=update_timer, daemon=True).start()


    except Exception as e:

        messagebox.showerror("Connection Failed", str(e))


def disconnect_vpn():

    global vpn_process, timer_running


    # For simplicity, we just terminate the VPN process here

    if vpn_process:

        vpn_process.terminate()

        try:

            vpn_process.wait(timeout=5)

        except subprocess.TimeoutExpired:

            vpn_process.kill()


    # Reset the buttons and timer

    dropdown.config(state="readonly")

    connect_btn.config(text="πŸ”— Connect", bootstyle="success", state="normal")

    disconnect_btn.place_forget()  # Hide the Disconnect button after disconnecting

    timer_label.config(text="")

    timer_running = False


# ---------------- GUI ----------------

app = tk.Tk()

app.title("🌐 Fuzzu VPN Connector")

app.geometry("400x280")

app.resizable(False, False)


style = Style("cyborg")


frame = LabelFrame(app, text="Select VPN Server:", padding=20)

frame.pack(pady=30, padx=20)


vpn_var = tk.StringVar()


create_auth_file()


# Dropdown menu for countries (VPN servers)

countries = ["UK", "US", "Germany", "France", "India"]

dropdown = Combobox(frame, textvariable=vpn_var, values=countries, width=30, state="readonly")

dropdown.pack(pady=10)

dropdown.set("UK")


# Connect Button

connect_btn = Button(frame, text="πŸ”— Connect", bootstyle="success", width=20, command=connect_vpn)

connect_btn.pack(pady=10)


# Disconnect Button

disconnect_btn = Button(frame, text="❌ Disconnect", bootstyle="danger", width=15, state="disabled", command=disconnect_vpn)


# Timer label (showing connection time)

timer_label = tk.Label(app, text="", font=("Segoe UI", 11), fg="lime")

timer_label.pack()


app.mainloop()

Comments

Popular posts from this blog

Is This News Real or Fake? πŸ€– AI Exposes the Truth | FuzzuTech Python App Demo

🚨 Python Intrusion Detection System (IDS) – Real-Time ML + Tkinter GUI Project | FuzzuTech

πŸš€ Simple Login & Registration System in Python Tkinter πŸ“±