Performance Optimization

Achieve 10-100x faster performance with the optional Rust module for large-scale network scanning.

Rust Performance Module

NetScan includes an optional Rust backend for CPU-intensive operations:

OperationPythonRustSpeedup
MAC normalize (1000x)12ms0.15ms~80x
CIDR expand (/16)850ms45ms~19x
OUI parse (30MB)3.2s180ms~18x
TCP scan (100 ports)5.1s0.3s~17x

Install Rust Module

# 1. Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env

# 2. Install maturin
pip3 install maturin

# 3. Build module
cd ~/.netscan
./build_rust.sh

Verify Installation

python3 ~/.netscan/helpers/fast_core.py
✓ Using Rust backend (10-100x faster)
  - normalize_mac: OK
  - expand_cidr: OK
  - parse_oui_file: OK
  - tcp_scan_async: OK

Auto-Fallback

The fast_core.py wrapper automatically uses Rust if available, otherwise falls back to Python:

from helpers.fast_core import normalize_mac, RUST_AVAILABLE

print(f"Using Rust: {RUST_AVAILABLE}")
mac = normalize_mac("001122334455")  # Works either way

Performance Tips

Increase Threads

# More concurrent connections
netscan -s --threads 100

# For large networks
netscan -s --threads 200 -t 10.0.0.0/16

Adjust Timeouts

# Shorter timeout for fast networks
netscan -s --timeout 2

# Longer for slow/remote networks
netscan -s --timeout 10

Use ARP Scan

# ARP is faster than ping (requires sudo)
sudo netscan -s

Limit Port Range

# Only common ports (faster)
netscan -f --ports 22,80,443

# vs all ports (slow)
netscan -f --ports 1-65535

Benchmarking

# Time a scan
time netscan -s -t 192.168.1.0/24

# Compare with/without Rust
NETSCAN_NO_RUST=1 time netscan -s  # Force Python
time netscan -s                     # Use Rust if available

Memory Usage

For very large networks (/8), consider:

# Stream results instead of buffering
netscan -s -t 10.0.0.0/8 --stream

# Or scan in chunks
for i in $(seq 0 255); do
  netscan -s -t "10.$i.0.0/16" -o "scan_10_$i.json"
done