Skip to content

Latest commit

Β 

History

History
109 lines (92 loc) Β· 5.67 KB

File metadata and controls

109 lines (92 loc) Β· 5.67 KB

Gemini Blueprint: NetGuard Pro Objective: Create a network monitoring and IP blocking application for Windows named "NetGuard Pro" using Python and the customtkinter library. The application should be a single, self-contained desktop app that allows users to view network connections and block or unblock IP addresses using the Windows Firewall.

Phase 1: Core Requirements & Setup Technology Stack:

Language: Python UI: customtkinter library. Image Handling: Pillow library (PIL). Core Libraries: subprocess, threading, re, json, datetime, tkinter.messagebox. Project Structure:

A single Python file named netguard_app.py. An image file named icon.png in the same directory (this will be used for the window icon and the title logo). The app will generate a netguard_config.json file to store blocked IPs. Main Application Class:

Create a class named NetGuardApp. The init method will set up the theme, window, and initial data, then call setup_ui(), load_blocked_ips(), and refresh_data(). A run() method will start the main application loop. Phase 2: UI Design & Layout (The setup_ui method) Step 1: Window Configuration

Set the customtkinter appearance mode to "dark" and the color theme to "blue". Create the main window (ctk.CTk()). Set the window title to "NetGuard Pro". Set the geometry to "635x700", min size to (630, 600), and max size to (640, 800). Step 2: Main Layout

Create a main CTkFrame that fills the entire window with a 10px padding. Step 3: Title Section

Create a transparent CTkFrame for the title area. Icon: Load icon.png using PIL.Image. Create a ctk.CTkImage from the loaded image with a size of (32, 32). Display this image in a CTkLabel packed to the left. Add 10px of horizontal padding to the right. Wrap this in a try...except block to handle FileNotFoundError or ImportError. Title Text: Create a CTkLabel with the text "NetGuard Pro - Network Monitor & Blocker". Use a bold CTkFont of size 24. Pack it to the left of the icon. Step 4: Author Label

Below the title frame, add a CTkLabel for the author credit: "Author: Wontfallow | GitHub: github.com/wontfallow | Twitter: @wontfallow" with a font size of 12. Step 5: Control Buttons & Status

Create a CTkFrame for control buttons. Refresh Button: A CTkButton with text "πŸ”„ Refresh". Clear All Blocks Button: A CTkButton with text "πŸ—‘οΈ Clear All Blocks", colored red. Status Label: A CTkLabel on the right side, initially showing "Ready". Step 6: Manual IP Entry Section

Create a CTkFrame for manual IP input. Add a bold title label: "πŸ“ Manual IP Entry & Filters". Filters: Add a CTkCheckBox to "Filter Out Multicast IPs". This should be on by default and should trigger a data refresh when toggled. IP Entry: Add a CTkEntry for IP address input, a red "βœ… Block Custom IP" button, and a "πŸ—‘οΈ Clear" button. Step 7: Tabbed Interface

Create a CTkTabview to hold the different data views. Add three tabs: "🏠 Internal Devices", "🌐 External Connections", and "🚫 Blocked IPs". For each tab, create a corresponding setup method (setup_internal_tab, etc.). Step 8: Table/List Setup (for each tab)

Each tab's setup method should create a header CTkFrame with column titles (IP Address, MAC Address, Status, Action, etc.). Below the header, add a CTkScrollableFrame that will be populated with data rows. Phase 3: Backend Functionality Step 1: Data Fetching (Network Commands)

get_arp_table(): Execute arp -a using subprocess.run. Parse the output using regex to extract IP and MAC addresses. Filter out loopback, broadcast, and (if toggled) multicast IPs. Only include local private IP ranges. get_external_connections(): Execute netstat -n using subprocess.run. Parse the output for established TCP connections, extracting remote IP, local port, and remote port. Filter out any connections to local/private IP addresses. Step 2: IP Blocking Logic

block_ip(ip_address): Construct a unique rule name (e.g., f"NetGuard_Block_{ip_address}"). Execute netsh advfirewall firewall add rule with dir=out, action=block, and the remote IP. On success, add the IP to the blocked_ips set and save. unblock_ip(ip_address): Construct the same rule name. Execute netsh advfirewall firewall delete rule to remove the block. On success, remove the IP from the blocked_ips set and save. Step 3: Data Persistence

save_blocked_ips(): Write the blocked_ips set to netguard_config.json. load_blocked_ips(): On startup, load the IPs from netguard_config.json into the blocked_ips set. Handle FileNotFoundError. Step 4: UI & Data Synchronization

refresh_data(): This method should run in a background thread (threading.Thread) to prevent the UI from freezing. The thread should call get_arp_table() and get_external_connections(). After fetching, it should schedule a UI update on the main thread using root.after(0, self.update_displays). update_displays(): This method calls individual update methods for each tab (update_internal_display, etc.). update_..._display() methods: These methods should first clear the existing rows in their respective scrollable frames. Then, iterate through the latest data (self.internal_devices, etc.) and call a helper method create_table_row() for each item. create_table_row(): This is a crucial helper method that creates a new CTkFrame for a row. It populates the row with CTkLabels for the data and a CTkButton for the action ("Block" or "Unblock"). The button's color and command should change depending on whether the IP is already blocked. Use a lambda function to pass the correct IP to the block_ip or unblock_ip method. Step 5: Final Execution

Use the standard if name == "main": block to instantiate the NetGuardApp class and call its run() method.