PyNetSketch is a robust, Python-based network management and reconnaissance tool designed as a Software Engineering demonstration and Proof of Concept (PoC).
It demonstrates advanced architectural patterns by featuring a Hybrid Engine that combines a flexible Python frontend (Tkinter) with a high-performance Rust core for critical I/O operations. The project is designed to bridge the gap between abstract network theory and visual understanding.
Notes: This project serves as an academic case study in Systems Integration, FFI (Foreign Function Interface), and Concurrency Patterns. This project is currently an early prototype and proof-of-concept system for the study of Software Engineering applied to a network monitoring tool
- Hybrid Engine (Python + Rust): Critical tasks (Port Scanning, Traffic Sniffing, TCP Connect) are offloaded to a compiled Rust core via PyO3, ensuring near-native performance while maintaining Python's ease of development.
- Modular Architecture (Refactored v1.5): The codebase follows strict Separation of Concerns (SoC), decoupling Network Logic (
net_utils), User Interface (interface/), and Server Control (host_functions). - Differential Traffic Monitor:
- Real-time visualization of network throughput using Rust (pnet) for packet capture.
- Visualizing "Total Traffic" vs. "Filtered Traffic" (isolate a specific IP's bandwidth usage against the network noise).
- Implements threaded callbacks with GIL release strategies to prevent UI starvation during high-load sniffing.
- Multi-Mode Scanning:
- Ping Host: Smart availability check (ICMP -> TCP Fallback).
- Trace Route: TCP-SYN based traceroute with "Hidden Node" detection.
- ARP Table Scan: Fast local subnet discovery with MAC Vendor resolution.
- Visual Topology Mapper: Generates a dynamic "hub-and-spoke" diagram of subnets and devices.
- Distributed Mode: Acts as a Probe Server for the PyNetSketch Mobile Companion app.
-
π₯οΈ Standalone (GUI): The classic desktop experience. Runs the modular Tkinter GUI locally.
- Best for: Deep diagnostics, traffic analysis, and visualization.
-
π‘ Server (Remote Probe): Turns the machine into a headless network probe.
- Auto-Discovery: Broadcasts presence via UDP.
- Remote Control: Accepts JSON commands via TCP sockets from mobile clients.
- Hardware Abstraction: Allows mobile devices to execute raw socket operations (like ARP scans) by proxying through the PC.
The project adheres to a modular design pattern:
gui_app.py: Main Controller. Initializes the app and orchestrates modules.rust_src/: Rust Core. Contains thepynetsketch_coresource code for high-performance sniffing and scanning.interface/: View Layer.scanner_tab.py: Treeview logic for ARP results.traffic_tab.py: Graph rendering and IP filtering logic.topology_tab.py: Canvas drawing logic for network maps.server_mode.py: UI for the Probe Server mode.startup_screen.py: View Layer. Handles the threaded loading sequence and visual startup feedback.
net_utils.py: Model / Middleware. Handles logic adaptation, Scapy fallback, and FFI calls to Rust.host_functions.py: Server logic for the mobile companion.utils.py: Thread management (run_in_background) and logging.
- Python 3.11+
- Rust Toolchain (for compiling the core):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - Npcap Driver and Npcap SDK (for windows)
NOTE: Rust setup can be skipped but the application will run python-only. This impacts performance so prefer not to
- libpcap headers: Required for compiling the Rust core packet capture features.
sudo apt-get install libpcap-dev # Debian
sudo dnf install libpcap-devel # Fedora
sudo pacman -S libpcap # Arch
-
Powershell is a must
-
Npcap Driver: Download from nmap.org/npcap. Though this check is handled during the startup cycle
-
Npcap SDK: To compile the Rust core, download the Npcap SDK. Extract in a known folder (as shown in example further down the chain, prefer making an
C:\NpcapSDKfolder) -
Windows SDK: If not already installed:
winget install --id=Microsoft.VisualStudio.2022.BuildTools --force --override "--quiet --wait --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"No further action should be necessary but if this still fails:
- Open Visual Studio Installer
- Click "modify" on Visual Studio Build Tools
- Make sure "Desktop development with C++" workload is checked
- On the right side panel, make sure to check "Windows 11 SDK" or "Windows 10 SDK"
-
Rust: If not already installed:
winget install rustupSet a system path to
C:\Users\<your user>\.cargo\binNote: This can be skipped but the application will run python-only, so prefer not to
Linux
python3 -m venv .venv
source .venv/bin/activate
Windows
python -m venv .venv
.\.venv\Scripts\activate
Note: You can do this outside of venv just fine, but this approach is recommended
Both systems
pip install -r requirements.txt
Linux
# Debian
sudo apt install python3-tk tk-dev gir1.2-webkit-6.0 libgirepository1.0-dev libcairo2-dev pkg-config python3-dev
# Fedora
sudo dnf install python3-tkinter webkitgtk6.0 gobject-introspection-devel cairo-devel python3-devel pkg-config
# Arch
sudo pacman -S tk # Arch only needs to run this line if tk complains it's not there
sudo pacman -S webkit2gtk webkit2gtk-5.0 gobject-introspection base-devel python-gobject cairo
Linux
cd rust_src
maturin develop --release
cd ..
Windows
$env:LIB = "C:\NpcapSDK\Lib\x64;" + $env:LIB # Ignore if already in PATH
cd rust_src
maturin develop --release
cd ..
NOTE: Sudo or running as administrator is recommended since this application needs permission to work with raw network packets.
Linux
sudo QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox" ./.venv/bin/python gui_app.py
No sandbox for webview compatibility
Windows
python gui_app.py
v.1.X - Early Engineering
- v1.0 - v1.2: Basic Monolithic Prototyping.
- v1.3 Rust Integration (Hybrid Engine).
- v1.4 Distributed Server Mode & Mobile Protocol.
- v1.5 Pre-release executable, fixes and error documentation.
- v1.6 (Milestone 1 - Modularization and Interfacing):
- Refactoring: Full GUI modularization.
- Performance: Implemented threaded Rust Sniffer with GIL release (fixed freezing).
- Feature: Differential Traffic Filtering.
- Fix: Solved Windows Interface Name mismatch (Adapter Pattern).
- v1.7 (Milestone 2 - Stability):
- Concurrency: Implemented Bidirectional Control Channel for Rust Sniffer (Non-blocking I/O cancellation <1s).
- Optimization: Added "Subnet Chunking" strategy for large network scans (eliminating Atomic Scapy freezes).
- Performance: Threaded Rust Sniffer with GIL release and Differential Traffic Filtering.
- v1.8 (Milestone 3 - Loading and Build fixes):
- UX Polish: Implemented custom Tkinter Splash Screen with transparency and procedural throbber.
- Architecture: "Lazy Loading" pattern implementation for visual feedback on app launch.
- Critical Fix: Resolved blocking I/O on Rust Core (Stop latency < 0.1s) and fixed PyInstaller binary shadowing.
- v1.9 (Traffic Monitor Refactor):
- Refactored TrafficTab: Implemented persistent packet tracking by hosts IP and improved adherence to SRP.
- IP list: Added right-click context menu with 'Filter by this Host' option.
v.2.X - Main features refinement and expansion
- v2.0 (Current - Map and Dark mode):
- Dark Mode: Implemented early version of dark mode in the push of a button (some things are a little broken but it works -ish)
- Map: Implemented API calls for geographical IP matching. Traceroute with DNS resolving now opens a map with a route traced between the geographical positions of each detected node.
- Fixes: Something broke rust core from functioning in traffic monitor. I fixed it. Again.
Click to expand
Status: FIXED in v1.7.
- Scanning a
/16network still relies on Scapy's atomic calls in Python mode, which can delay UI updates. The Rust implementation mitigates this but requires further optimization for massive ranges.
Solution:
- Implemented the Subnet Chunking logic in net_utils.py. Any target network larger than a /24 is now split into smaller /24 blocks. The scanner processes these blocks sequentially, checking for thread cancellation signals (stop_event) and updating the UI progress bar between each chunk, preventing the interface from freezing during massive scans.
Status: FIXED in v1.6.
- Logs currently write to the temporary execution directory when frozen with PyInstaller. Needs logic to detect
sys.frozen.
Solution:
- Refactored utils.py to implement Context-Aware Path Detection.
Status: FIXED in v1.7.
- While the Python UI now remains responsive (due to
py.allow_threads), stopping a Rust operation instantly requires the Rust loop to check a shared atomic flag. Currently, it stops after the current batch/timeout (approx. 1s latency).
Solution:
- Established a Bidirectional Control Channel via FFI. Configured the Rust
pnetchannel with a 100ms read timeout to prevent blocking on idle networks. The Python callback now returns a boolean status.
Status: FIXED in v1.6.
- Previously, the app failed to identify the correct interface GUID on Windows. Solution:
- Implemented an automatic translation layer in
net_utils.pythat maps Scapy's detected device (Friendly Name) to the Npcap GUID required by the Rustpnetlibrary.
Status: CREATED AND PARTIALLY FIXED in v2.0.
- The initial Dark Mode implementation resulted in visual glitches where certain widgets did not inherit the theme correctly, creating a mixed "Frankenstein" look.
- Combobox (Dropdowns): In readonly state, the background remained system-grey. Crucially, the dropdown list (popdown) often rendered with white text on a white background (invisible) or failed to revert to black text when switching back to Light Mode.
- Canvas Elements: The Network Topology and Traffic Monitor graphs retained their original background colors upon toggling the theme.
- Native Elements: The Windows Title Bar and Scrollbars remained in the default light system style, breaking the "Cyberpunk" aesthetic.
Solution:
- Advanced Styling: Implemented comprehensive ttk.Style mapping using style.map to force specific colors for readonly and disabled states on Buttons and Comboboxes.
- Global Overrides: Used root.option_add('TComboboxListbox*') and Listbox to forcibly style the OS-native dropdown menus, preventing style leakage between modes.
- Dynamic Canvas Updates: Added dedicated update_theme(is_dark) methods in traffic_tab.py and topology_tab.py to programmatically reconfigure Canvas backgrounds and redraw vector elements (nodes/lines) with contrast-appropriate palettes.
- Windows API Integration: Implemented a ctypes call to dwmapi to force the Windows 10/11 Title Bar to respect the immersive dark mode attribute.
To control this tool from your phone, check the PyNetSketch Mobile App.
NOTE: Development environment setup is necessary to run the mobile app.
Check the troubleshooting guide
This project is licensed under the MIT License.
Educational Use Only. This tool involves raw socket manipulation and packet interception. Use only on networks you own or have permission to audit.



