This document describes the implementation of the Port Explorer module for PNTools, which provides port scanning capabilities with both native TCP scanning and optional nmap integration.
Located in src-tauri/src/:
-
modules/port_scanner.rs - Core port scanning logic
- Native TCP-based port scanning using Rust's standard library
- Nmap integration for advanced scanning
- Service name detection for common ports
- Configurable timeout and port range support
-
commands/port_scanner.rs - Tauri command handlers
scan_ports_command: Main scanning function exposed to frontendcheck_nmap_available: Check if nmap is installed on the system
Located in src/modules/tauri/components/port-explorer/:
- index.tsx - Main React component
- User interface for configuring and running port scans
- Interactive results table with filtering and sorting
- Real-time scanning status and progress
- Error handling and nmap availability detection
- Uses Rust's
TcpStream::connect_timeoutfor fast, reliable port checking - No external dependencies required
- Cross-platform support (Windows, macOS, Linux)
- Configurable timeout per port
- Optional use of nmap for more advanced scanning
- Automatic detection of nmap availability
- Parses nmap output for enhanced service detection
- Fallback to native scanning if nmap fails
Common services automatically detected:
- FTP (20, 21)
- SSH (22)
- Telnet (23)
- SMTP (25)
- DNS (53)
- HTTP (80, 8080)
- HTTPS (443, 8443)
- SMB (445)
- MySQL (3306)
- RDP (3389)
- PostgreSQL (5432)
- VNC (5900)
- Redis (6379)
- MongoDB (27017)
- Clean, intuitive design using Ant Design components
- Real-time scan progress indication
- Results displayed in sortable, filterable table
- Visual status indicators (green/red tags for open/closed ports)
- Summary statistics showing open vs. scanned ports
fn scan_ports_command(
host: String,
start_port: u16,
end_port: u16,
use_nmap: bool,
timeout_ms: u64,
) -> Result<Vec<PortScanResult>, String>Parameters:
host: Target hostname or IP addressstart_port: First port in range to scan (1-65535)end_port: Last port in range to scan (1-65535)use_nmap: If true, use nmap; if false, use native scanningtimeout_ms: Connection timeout in milliseconds
Returns: List of port scan results or error message
fn check_nmap_available() -> boolReturns: true if nmap is installed and accessible, false otherwise
struct PortScanResult {
port: u16, // Port number
is_open: bool, // Whether port is open
service: Option<String>, // Detected service name
}- Launch PNTools application
- Navigate to: Tauri > PortExplorer
- Configure scan parameters:
- Host:
127.0.0.1(or any IP/hostname) - Start Port:
1 - End Port:
1024 - Timeout:
1000ms - Use nmap: Toggle on/off
- Host:
- Click "Start Scan"
- View results in the table
import { invoke } from '@tauri-apps/api/core';
// Scan ports 80-443 on localhost
const results = await invoke('scan_ports_command', {
host: '127.0.0.1',
startPort: 80,
endPort: 443,
useNmap: false,
timeoutMs: 1000,
});
// Check if nmap is available
const nmapAvailable = await invoke('check_nmap_available');src-tauri/src/modules/port_scanner.rs- Port scanning logicsrc-tauri/src/commands/port_scanner.rs- Tauri command handlerssrc/modules/tauri/components/port-explorer/index.tsx- React UI componentsrc/modules/tauri/components/port-explorer/README.md- Module documentation
src-tauri/src/modules/mod.rs- Added port_scanner modulesrc-tauri/src/commands/mod.rs- Added port_scanner commandssrc-tauri/src/main.rs- Registered new Tauri commandssrc/modules/tauri/index.tsx- Added PortExplorer routeREADME.md- Added feature documentation
- Authorization: Port scanning should only be performed on networks/systems you own or have explicit permission to scan
- Rate Limiting: Consider adding rate limiting for large port ranges to avoid overwhelming the target
- Logging: Scans are not logged by default; consider adding audit logging for production use
- Error Handling: Proper error handling prevents crashes and provides useful feedback
- Native scanning is fastest for small port ranges (< 100 ports)
- Nmap is recommended for large port ranges (> 1000 ports)
- Timeout affects scan duration: lower timeout = faster scans but more false negatives
- Parallel scanning is not implemented to avoid overwhelming the target system
Potential improvements for future versions:
- UDP port scanning support
- Parallel/concurrent scanning with configurable thread pool
- Export results to CSV/JSON
- Scan history and saved configurations
- Port range presets (common ports, all ports, etc.)
- Integration with vulnerability databases
- Network range scanning (CIDR notation)
- Custom service detection rules
The module has been verified to:
- ✅ Compile successfully (both Rust and TypeScript)
- ✅ Pass type checking
- ✅ Integrate properly with existing Tauri commands
- ✅ Follow existing code patterns and structure
Manual testing recommended:
- Test scanning localhost (127.0.0.1)
- Test scanning with various port ranges
- Test with and without nmap installed
- Test timeout adjustments
- Verify service detection accuracy
serde- Serialization/deserializationstd::net::TcpStream- TCP connectionsstd::process::Command- Execute nmapstd::time::Duration- Timeout handling
@tauri-apps/api- Tauri API bindingsantd- UI componentsreact- UI framework
No additional dependencies were added to the project.