A cross-platform terminal user interface for discovering and listing nearby WiFi networks.
wif-tui.mp4
- Real-time WiFi network scanning
- Signal strength visualization with bars
- Channel and security protocol display
- Keyboard navigation
- Built-in log viewer for debugging
# Build
cargo build --release
# Run
./target/release/wifi-tui| Key | Action |
|---|---|
r |
Refresh/rescan networks |
j / ↓ |
Move selection down |
k / ↑ |
Move selection up |
l |
Toggle log panel |
q / Esc |
Quit |
| Platform | Implementation | Status |
|---|---|---|
| macOS | system_profiler SPAirPortDataType |
✅ Implemented |
| Linux | nmcli (NetworkManager) / iw fallback |
✅ Implemented |
| Windows | wlanapi.dll raw FFI |
✅ Implemented |
The Linux scanner uses two methods:
- nmcli (preferred) - Works without root on systems with NetworkManager
- iw (fallback) - Requires root privileges (
sudo wifi-tui)
Most desktop distributions (Ubuntu, Fedora, etc.) pre-install NetworkManager.
The Windows scanner uses raw FFI to the Native WiFi API (wlanapi.dll):
- No external crates required (demonstrates FFI skills)
- RAII wrapper ensures proper handle cleanup
- Retrieves SSID, BSSID, channel, signal strength, and security type
- Works on Windows 7 and later
src/
├── main.rs # Entry point, event loop
├── app.rs # Application state
├── ui.rs # Ratatui rendering
├── lib.rs # Library exports
└── scanner/
├── mod.rs # Scanner trait, types
├── macos.rs # macOS: system_profiler
├── linux.rs # Linux: nmcli / iw
└── windows.rs # Windows: wlanapi.dll
Why not CoreWLAN on macOS?
CoreWLAN requires Location Services permission, which is problematic for CLI tools:
- CLI tools can't reliably trigger the permission dialog
- They inherit permissions from the parent terminal app
- Most terminals don't have Location permission by default
See ffi.md for detailed documentation.
Why system_profiler?
system_profiler SPAirPortDataType provides WiFi network information without requiring Location Services or root access.
The Windows implementation (src/scanner/windows.rs) uses raw FFI to the Native WiFi API. This was chosen to demonstrate FFI skills without relying on external crates like windows-sys.
Safety measures implemented:
-
RAII Handle Management -
WlanHandlewrapper ensuresWlanCloseHandleis always called viaDrop, even on error paths -
Memory Management - All Windows-allocated memory (
WLAN_INTERFACE_INFO_LIST,WLAN_AVAILABLE_NETWORK_LIST,WLAN_BSS_LIST) is freed withWlanFreeMemorybefore returning -
Pointer Validation - Return codes checked before dereferencing pointers;
ERROR_SUCCESSrequired -
Struct Layout - All structs use
#[repr(C)]with field order matching official Microsoft documentation
API functions used:
WlanOpenHandle/WlanCloseHandle- Connection lifecycleWlanEnumInterfaces- Discover wireless adaptersWlanScan- Trigger fresh network scanWlanGetAvailableNetworkList- Get visible networksWlanGetNetworkBssList- Get BSSID and channel info
Both macOS and Linux implementations use safe Rust only, spawning system commands (system_profiler, nmcli, iw) and parsing their text output. See ffi.md for why CoreWLAN FFI was abandoned on macOS.
Only three crates as required:
ratatui- TUI frameworkcrossterm- Terminal backendtracing/tracing-subscriber- Structured logging
To test WiFi scanning without the TUI:
cargo run --bin scan-testExample output:
WiFi available: true
Interface: en0
Found 4 networks:
████ | 2.4GHz | -50 dBm | WPA2 | MyNetwork
███░ | 5GHz | -65 dBm | WPA2 | CoffeeShop
██░░ | 2.4GHz | -76 dBm | WPA2 | Neighbor
█░░░ | 2.4GHz | -85 dBm | Open | FreeWiFi
- macOS 10.15+ (Catalina or later)
- WiFi hardware enabled
- NetworkManager (for non-root scanning) or
iwpackage - WiFi hardware enabled
- Windows 7 or later
- WLAN AutoConfig service running (default on Windows)
- WiFi hardware enabled
- Rust 1.70+
- Connect to networks - Allow users to select a network and connect directly from the TUI
- Password input - Secure text input for entering WPA/WPA2/WPA3 credentials
- Forget networks - Remove saved network profiles
- Network details view - Expandable panel showing BSSID, exact channel, PHY mode, and more
- Auto-refresh - Configurable automatic rescanning interval
- Signal history graph - Track signal strength over time for selected network