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
use clap::{Parser, Subcommand};
use clap_complete::Shell;
#[derive(Parser)]
#[command(name = "netscli", version, about = "Modern network scanner", long_about = None)]
pub struct Cli {
/// Max in-flight network operations (default 256; clamped to [1, 1024];
/// mDNS discovery sub-caps internally at 32). Lower this on fragile home
/// gateways that struggle with hundreds of simultaneous probes.
#[arg(short = 'j', long, global = true, value_name = "N")]
pub concurrency: Option<usize>,
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Subcommand)]
pub enum Commands {
/// Guided first-run setup / dependency wizard
Setup {
/// Print recommended commands only (do not execute)
#[arg(long)]
print: bool,
/// Execute recommended install commands (may prompt for sudo)
#[arg(long)]
execute: bool,
},
/// Dependency and capability diagnostics (headless)
Doctor {
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Discover live hosts on a network subnet
Discover {
/// CIDR subnet (e.g., 192.168.1.0/24)
subnet: Option<String>,
/// Resolve hostnames
#[arg(long)]
resolve: bool,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Scan TCP ports on a host
Scan {
/// Host to scan
host: String,
/// Ports to scan (comma-separated or range)
#[arg(short, long)]
ports: Option<String>,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Comprehensive host inspection
Inspect {
/// Host to inspect
host: String,
/// Ports to scan
#[arg(short, long)]
ports: Option<String>,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Network sweep (discover hosts then scan ports)
Sweep {
/// CIDR subnet
subnet: Option<String>,
/// Ports to scan
#[arg(short, long)]
ports: Option<String>,
/// Resolve hostnames
#[arg(long)]
resolve: bool,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// DNS lookup
Dns {
/// Host to lookup
host: String,
/// Record type (A, AAAA, CNAME, MX, NS, TXT, SRV, PTR, SOA, CAA, ALL/ANY)
#[arg(long)]
record: Option<String>,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Reverse DNS lookup
Reverse {
/// IP address to reverse lookup
ip: String,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Ping a host (basic)
Ping {
/// Host to ping (IP or hostname)
host: String,
/// Number of pings to send
#[arg(short = 'c', long, default_value_t = 4)]
count: u32,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Trace route to a host (hops)
Trace {
/// Host to trace (IP or hostname)
host: String,
/// Resolve hop hostnames (slower)
#[arg(long)]
resolve: bool,
/// Maximum hops
#[arg(long, default_value_t = 30)]
max_hops: u32,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Show or manage ARP table
#[command(group(
clap::ArgGroup::new("arp_action")
.args(["add", "delete", "clear"])
.multiple(false)
))]
Arp {
/// Add an ARP entry (requires --ip and --mac)
#[arg(long)]
add: bool,
/// Delete an ARP entry (requires --ip)
#[arg(long)]
delete: bool,
/// Clear ARP table
#[arg(long)]
clear: bool,
/// IP address for add/delete
#[arg(long)]
ip: Option<String>,
/// MAC address for add
#[arg(long)]
mac: Option<String>,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Capture network packets to PCAP file
#[cfg(feature = "pcap")]
#[command(group(
// Either --check (list devices, don't capture) or a real capture
// with --interface. This keeps the old `--check` UX ergonomic —
// users shouldn't have to supply a dummy interface just to list.
clap::ArgGroup::new("pcap_mode")
.args(["interface", "check"])
.required(true)
.multiple(true)
))]
Pcap {
/// Network interface name (required unless --check is used)
#[arg(short, long)]
interface: Option<String>,
/// Filter expression (BPF)
#[arg(long)]
filter: Option<String>,
/// Duration seconds
#[arg(long)]
duration: Option<u64>,
/// Max packets
#[arg(long)]
max_packets: Option<usize>,
/// Output file
#[arg(long, default_value = "capture.pcap")]
output: String,
/// Only check pcap support and list capture devices
#[arg(long)]
check: bool,
/// Output JSON
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// List interfaces
Interfaces {
#[arg(long)]
json: bool,
/// Output YAML
#[arg(long)]
yaml: bool,
},
/// Discover devices on the local network via mDNS/DNS-SD (Bonjour)
Mdns {
/// Browse window in milliseconds. Longer = more devices found,
/// since many announce on a multi-second cadence.
#[arg(long, default_value_t = 3000)]
timeout_ms: u64,
/// Service types to browse (repeatable). Defaults to a curated set
/// of common types (_http._tcp, _ssh._tcp, _airplay._tcp, etc.).
#[arg(long = "type", short = 't')]
service_types: Vec<String>,
#[arg(long)]
json: bool,
#[arg(long)]
yaml: bool,
},
/// Start MCP server for AI agents
#[command(name = "serve")]
McpServe,
/// Print shell-completion script for the requested shell.
///
/// Typical usage:
/// bash: netscli completions bash > ~/.local/share/bash-completion/completions/netscli
/// zsh: netscli completions zsh > ~/.zsh/completions/_netscli
/// fish: netscli completions fish > ~/.config/fish/completions/netscli.fish
/// powershell: netscli completions powershell > $PROFILE/netscli.ps1
#[command(name = "completions")]
Completions { shell: Shell },
/// Print the roff-format man page to stdout.
///
/// Typical usage: netscli man | gzip > /usr/share/man/man1/netscli.1.gz
#[command(name = "man")]
Man,
/// Manage MCP server auto-start (systemd service)
McpService {
/// Generate systemd user service file
#[arg(long)]
install: bool,
/// Remove systemd user service file
#[arg(long)]
uninstall: bool,
/// Show service status
#[arg(long)]
status: bool,
},
}