r-lancli 0.1.5

A command-line interface for performing network scanning operations on local area networks (LANs)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# r-lancli

A command-line interface for performing network scanning operations on local area networks (LANs). This CLI tool uses the [r-lanlib](../lib/README.md) library to provide comprehensive network reconnaissance capabilities.

## Features

- **ARP Scanning**: Discover active devices on your network using Address Resolution Protocol
- **SYN Port Scanning**: Detect open ports on discovered devices using TCP SYN packets
- **Flexible Target Specification**: Support for individual IPs, IP ranges, and CIDR blocks
- **Port Range Scanning**: Scan specific ports or port ranges
- **Device Information**: Optional MAC address vendor lookup and hostname resolution
- **Multiple Output Formats**: Human-readable tables or JSON for programmatic use
- **Network Interface Selection**: Choose specific network interfaces for scanning
- **Configurable Timeouts**: Adjust scan timing for different network conditions

## Installation

### Prerequisites

- **Root privileges required**: Network scanning requires raw socket access
- **Rust 1.89.0+** - Install via [rustup.rs]https://rustup.rs/

### Building from Source

```bash
# Clone the repository
git clone https://github.com/robgonnella/r-lanscan
cd r-lanscan

# Build the CLI tool
cargo build --release -p r-lancli

# The binary will be available at ./target/release/r-lancli
```

## Quick Start

### Basic Network Scan

Scan your entire local network (discovers devices and scans all ports):

```bash
sudo r-lancli
```

### ARP-Only Device Discovery

Quickly discover devices without port scanning:

```bash
sudo r-lancli --arp-only --vendor --host-names
```

### Scan Specific Targets

Scan specific IP addresses or ranges:

```bash
sudo r-lancli --targets 192.168.1.1,192.168.1.10-20,10.0.0.0/24
```

### Port-Specific Scanning

Scan only common ports:

```bash
sudo r-lancli --ports 22,80,443,8080,8443
```

### JSON Output

Get results in JSON format for scripting:

```bash
sudo r-lancli --json --quiet > scan_results.json
```

## Command Line Options

### Target Specification

#### `--targets, -t <TARGETS>`

Comma-separated list of scan targets. Supports:

- **Individual IPs**: `192.168.1.1`
- **IP ranges**: `192.168.1.1-192.168.1.100`
- **CIDR blocks**: `192.168.1.0/24`, `10.0.0.0/16`

**Default**: Uses the CIDR block of the selected network interface

**Examples**:

```bash
# Single IP
sudo r-lancli --targets 192.168.1.1

# Multiple IPs
sudo r-lancli --targets 192.168.1.1,192.168.1.5,192.168.1.10

# IP range
sudo r-lancli --targets 192.168.1.1-192.168.1.50

# CIDR block
sudo r-lancli --targets 192.168.1.0/24

# Mixed specification
sudo r-lancli --targets 192.168.1.1,192.168.1.10-20,10.0.0.0/24
```

#### `--ports, -p <PORTS>`

Comma-separated list of ports and port ranges to scan.

**Default**: `1-65535` (all ports)

**Examples**:

```bash
# Common ports
sudo r-lancli --ports 22,80,443

# Port ranges
sudo r-lancli --ports 1-1000,8000-9000

# Mixed specification
sudo r-lancli --ports 22,80,443,8000-9000,3389
```

### Scan Options

#### `--arp-only`

Perform only ARP scanning, skipping SYN port scanning.

**Use case**: Quick device discovery without the time overhead of port scanning.

```bash
sudo r-lancli --arp-only --vendor --host-names
```

#### `--vendor`

Enable MAC address vendor lookup to identify device manufacturers.

```bash
sudo r-lancli --vendor
```

#### `--host-names`

Enable reverse DNS lookup to resolve hostnames for discovered devices.

```bash
sudo r-lancli --host-names
```

### Network Configuration

#### `--interface, -i <INTERFACE>`

Select a specific network interface for scanning.

**Default**: Automatically selects the default network interface

**Examples**:

```bash
# Use specific interface
sudo r-lancli --interface eth0

# List available interfaces (use system tools)
ip link show  # Linux
ifconfig      # macOS/BSD
```

#### `--source-port <SOURCE_PORT>`

Set the source port for outgoing scan packets.

**Default**: Automatically selects an available port

```bash
sudo r-lancli --source-port 12345
```

### Output Options

#### `--json`

Output results in JSON format instead of human-readable tables.

**Use case**: Programmatic processing, integration with other tools.

```bash
sudo r-lancli --json > results.json
```

#### `--quiet, -q`

Suppress progress messages, only show final results.

**Use case**: Cleaner output for scripting and automation.

```bash
sudo r-lancli --quiet --json
```

### Timing and Performance

#### `--idle-timeout-ms <MILLISECONDS>`

Set the idle timeout for scan operations.

**Default**: `10000` (10 seconds)

**Use case**: Adjust for slower networks or more thorough scanning.

```bash
# Faster scanning (less thorough)
sudo r-lancli --idle-timeout-ms 5000

# Slower scanning (more thorough)
sudo r-lancli --idle-timeout-ms 30000
```

### Debugging

#### `--debug`

Enable debug logging for troubleshooting scan operations.

```bash
sudo r-lancli --debug
```

## Output Formats

### Table Format (Default)

**ARP Results**:

```
+---------------+----------+-------------------+------------------------+
| IP            | HOSTNAME | MAC               | VENDOR                 |
+---------------+----------+-------------------+------------------------+
| 192.168.1.1   | router   | aa:bb:cc:dd:ee:ff | Netgear                |
| 192.168.1.100 | laptop   | 11:22:33:44:55:66 | Apple, Inc.            |
| 192.168.1.150 |          | 99:88:77:66:55:44 | Samsung Electronics    |
+---------------+----------+-------------------+------------------------+
```

**SYN Results** (with port scanning):

```
+---------------+----------+-------------------+------------------------+-------------+
| IP            | HOSTNAME | MAC               | VENDOR                 | OPEN_PORTS  |
+---------------+----------+-------------------+------------------------+-------------+
| 192.168.1.1   | router   | aa:bb:cc:dd:ee:ff | Netgear                | 22, 80, 443 |
| 192.168.1.100 | laptop   | 11:22:33:44:55:66 | Apple, Inc.            | 22, 5900    |
+---------------+----------+-------------------+------------------------+-------------+
```

### JSON Format

```json
[
  {
    "hostname": "router",
    "ip": "192.168.1.1",
    "mac": "aa:bb:cc:dd:ee:ff",
    "vendor": "Netgear",
    "is_current_host": false,
    "open_ports": [
      { "id": 22, "service": "ssh" },
      { "id": 80, "service": "http" },
      { "id": 443, "service": "https" }
    ]
  }
]
```

## Common Use Cases

### Network Discovery

Discover all devices on your local network:

```bash
sudo r-lancli --arp-only --vendor --host-names
```

### Security Auditing

Comprehensive scan with detailed information:

```bash
sudo r-lancli --vendor --host-names --json > network_audit.json
```

### Service Discovery

Find devices running specific services:

```bash
sudo r-lancli --ports 22,80,443,3389,5900 --vendor
```

### Quick Port Check

Check if specific hosts have certain ports open:

```bash
sudo r-lancli --targets 192.168.1.1,192.168.1.100 --ports 22,80,443
```

### Subnet Scanning

Scan multiple subnets:

```bash
sudo r-lancli --targets 192.168.1.0/24,192.168.2.0/24 --arp-only
```

## Integration and Automation

### Bash Scripting

```bash
#!/bin/bash

# Perform scan and save results
sudo r-lancli --json --quiet > network_scan.json

# Process results with jq
jq '.[] | select(.open_ports | length > 0)' network_scan.json > devices_with_ports.json

echo "Found $(jq 'length' devices_with_ports.json) devices with open ports"
```

### Python Integration

```python
import json
import subprocess

# Run scan
result = subprocess.run([
    'sudo', 'r-lancli',
    '--json', '--quiet',
    '--targets', '192.168.1.0/24'
], capture_output=True, text=True)

# Parse results
devices = json.loads(result.stdout)

for device in devices:
    print(f"Device: {device['ip']} ({device['hostname']})")
    if 'open_ports' in device:
        ports = [str(port['id']) for port in device['open_ports']]
        print(f"  Open ports: {', '.join(ports)}")
```

### Cron Jobs

```bash
# Add to crontab for periodic scanning
# Run every hour and log changes
0 * * * * /usr/local/bin/r-lancli --json --quiet > /var/log/network-scan-$(date +\%Y\%m\%d-\%H).json 2>&1
```

## Troubleshooting

### Permission Errors

**Error**: `permission denied: must run with root privileges`

**Solution**: Run with `sudo`:

```bash
sudo r-lancli
```

### Network Interface Issues

**Error**: `cannot find interface`

**Solutions**:

1. List available interfaces:

   ```bash
   # Linux
   ip link show

   # macOS/BSD
   ifconfig
   ```

2. Specify interface explicitly:
   ```bash
   sudo r-lancli --interface eth0
   ```

### No Results Found

**Possible causes**:

- Firewall blocking scan packets
- Network devices configured to ignore ARP/ICMP
- Incorrect network range specified

**Solutions**:

1. Increase timeout:

   ```bash
   sudo r-lancli --idle-timeout-ms 30000
   ```

2. Use debug mode:

   ```bash
   sudo r-lancli --debug
   ```

3. Verify network configuration:
   ```bash
   # Check your IP and network
   ip route show  # Linux
   route -n get default  # macOS
   ```

### Performance Issues

**For large networks**:

1. Use ARP-only for initial discovery:

   ```bash
   sudo r-lancli --arp-only
   ```

2. Limit port ranges:

   ```bash
   sudo r-lancli --ports 1-1000
   ```

3. Scan smaller subnets:
   ```bash
   sudo r-lancli --targets 192.168.1.0/26
   ```

## Security and Ethics

### Responsible Usage

- **Only scan networks you own or have explicit permission to test**
- **Be aware that network scanning may be logged by security systems**
- **Some networks may consider scanning as hostile activity**
- **Consider network impact - scanning can generate significant traffic**

### Legal Considerations

- Network scanning may be restricted by local laws and regulations
- Corporate networks often have policies against unauthorized scanning
- Always obtain proper authorization before scanning

## License

This project is dual-licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE]../LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License ([LICENSE-MIT]../LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

## Related Tools

- **[r-lanlib]../lib/README.md**: The underlying Rust library powering this CLI
- **[r-lanterm]../term/README.md**: Terminal UI application for interactive network management