r-lanlib
A Rust library crate for performing network scanning operations on any local area network (LAN). This is the Rust version of the go-lanscan package.
Features
- ARP Scanning: Discover devices on your network using Address Resolution Protocol
- SYN Scanning: Detect open ports on discovered devices using TCP SYN packets
- Full Scanning: Combined ARP and SYN scanning in a single operation
- Vendor Detection: Identify device manufacturers using MAC address lookup
- Hostname Resolution: Resolve hostnames for discovered devices
- Async Communication: Channel-based communication for real-time scan results
- Flexible Targeting: Support for CIDR blocks, IP ranges, and port ranges
Requirements
- Root privileges required: This library performs raw packet operations that require elevated permissions
- Rust 1.89.0+ with 2024 edition support
Installation
Quick Start
Basic ARP Scanning
use ;
use ;
// Get default network interface
let interface = get_default_interface
.expect;
// Create packet wire (reader/sender)
let wire = default
.expect;
// Define IP targets (scan entire subnet)
let ip_targets = new;
// Create communication channel
let = ;
// Configure scanner
let scanner = new;
// Start scanning (runs in background thread)
let handle = scanner.scan;
// Process results in real-time
let mut devices = Vecnew;
loop
handle.join.expect;
println!;
SYN Port Scanning
use ;
// Define target devices (from previous ARP scan or manual)
let devices = vec!;
// Define port targets
let port_targets = new;
let scanner = new;
// Process SYN scan results
let mut results = Vecnew;
let handle = scanner.scan;
loop
Full Scanning (ARP + SYN)
use ;
let scanner = new;
// This will perform ARP discovery first, then SYN scan on found devices
let handle = scanner.scan;
API Reference
Core Modules
network
Provides helpers for selecting network interfaces:
get_default_interface()- Get the default network interfaceget_interface(name)- Get a specific interface by nameget_available_port()- Find an available port for scanning
packet
Low-level packet creation and transmission:
wire::default(interface)- Create default packet reader/sender pair- Various packet builders for ARP, SYN, RST packets
scanners
Main scanning implementations:
ARPScanner- Discover devices using ARPSYNScanner- Scan ports on known devicesFullScanner- Combined ARP + SYN scanning
targets
Target specification utilities:
ips::IPTargets- Define IP ranges and CIDR blocksports::PortTargets- Define port ranges and individual ports
Data Structures
Device
Represents a discovered network device:
Port
Represents a network port:
PortSet
Wrapper around HashSet<Port> with convenience methods:
;
ScanMessage
Messages sent over the notification channel:
Target Specification
IP Targets
// CIDR blocks
new;
// IP ranges
new;
// Individual IPs
new;
Port Targets
// Port ranges
new;
// Individual ports
new;
// Mixed specification
new;
Examples
The library includes several complete examples in the examples/ directory:
arp-scanner.rs- Basic ARP device discoverysyn-scanner.rs- Port scanning on known devicesfull-scanner.rs- Complete network reconnaissance
Run examples from the workspace root with:
Configuration Options
Scanner Timeouts
idle_timeout- How long to wait for responses before concluding scan- Default: 10 seconds (10,000ms)
- Recommended: 5-30 seconds depending on network size and latency
Scanner Features
include_vendor- Perform MAC address vendor lookup using IEEE OUI databaseinclude_host_names- Resolve hostnames via reverse DNS lookupsource_port- Source port for scan packets (auto-selected if not specified)
Performance Tuning
- Concurrent scanning: Multiple threads handle packet I/O for optimal throughput
- Memory efficiency: Zero-copy packet processing where possible
- Network-aware: Automatic rate limiting to prevent network congestion
- Timeout optimization: Adaptive timeouts based on network response times
Security Considerations
- Requires root privileges for raw socket access on Unix-like systems
- Network scanning may be restricted by network policies and firewalls
- Built-in rate limiting prevents network congestion and reduces detection risk
- Minimal network footprint: Optimized packet sizes and timing
- Memory safety: Rust's ownership system prevents buffer overflows and memory corruption
- Use responsibly and only on networks you own or have permission to scan
- Logging: All scan activities can be logged for audit purposes
Ethical Usage Guidelines
- Always obtain proper authorization before scanning
- Respect network resources and avoid aggressive scanning
- Be aware that scanning activities may be logged by network security systems
- Consider the impact on network performance during large-scale scans
Error Handling
The library uses RLanLibError for comprehensive error reporting:
License
This project is dual-licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Related Projects
- go-lanscan - Original Go implementation
- r-lancli - Command-line interface using this library
- r-lanterm - Terminal UI application using this library