multiprobe 0.3.1

Enterprise-grade multi-protocol network probing with Paris Traceroute, path analytics, MTU discovery, and TLS analysis
Documentation
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
//! multiprobe CLI - Network probing and path analysis tool
//!
//! Usage: multiprobe <COMMAND> [OPTIONS] <TARGET>

use std::time::Duration;

use clap::{Parser, Subcommand};
use multiprobe::{
    Probe, Classifier, BidirectionalServer,
    paris::ParisMode,
};

#[derive(Parser)]
#[command(name = "multiprobe")]
#[command(author = "Biplab Das")]
#[command(version)]
#[command(about = "Multi-protocol network probing and path analysis tool")]
#[command(long_about = "Enterprise-grade network probing with Paris Traceroute, \
    path analytics, MTU discovery, bufferbloat detection, and bidirectional path analysis.")]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// TCP connect probe
    Tcp {
        /// Target hostname or IP
        target: String,
        /// Port to probe
        port: u16,
        /// Timeout in seconds
        #[arg(short, long, default_value = "5")]
        timeout: u64,
    },

    /// UDP probe
    Udp {
        /// Target hostname or IP
        target: String,
        /// Port to probe
        port: u16,
        /// Timeout in seconds
        #[arg(short, long, default_value = "5")]
        timeout: u64,
    },

    /// ICMP ping (requires elevated privileges)
    Icmp {
        /// Target hostname or IP
        target: String,
        /// Timeout in seconds
        #[arg(short, long, default_value = "5")]
        timeout: u64,
        /// TTL (time to live)
        #[arg(long)]
        ttl: Option<u8>,
    },

    /// TLS handshake analysis
    Tls {
        /// Target hostname or IP
        target: String,
        /// Port (default 443)
        #[arg(short, long, default_value = "443")]
        port: u16,
        /// Timeout in seconds
        #[arg(short, long, default_value = "10")]
        timeout: u64,
        /// Skip certificate verification
        #[arg(long)]
        skip_verify: bool,
    },

    /// Standard traceroute (requires elevated privileges)
    Traceroute {
        /// Target hostname or IP
        target: String,
        /// Maximum hops
        #[arg(short, long, default_value = "30")]
        max_hops: u8,
        /// Timeout per hop in seconds
        #[arg(short, long, default_value = "2")]
        timeout: u64,
    },

    /// Paris Traceroute - ECMP-aware path discovery (requires elevated privileges)
    Paris {
        /// Target hostname or IP
        target: String,
        /// Maximum hops
        #[arg(short, long, default_value = "30")]
        max_hops: u8,
        /// Timeout per hop in seconds
        #[arg(short, long, default_value = "2")]
        timeout: u64,
        /// Probe mode: udp, icmp, tcp
        #[arg(long, default_value = "udp")]
        mode: String,
        /// Detect load balancing
        #[arg(long)]
        detect_lb: bool,
    },

    /// Multi-protocol probe (TCP, UDP, ICMP together)
    Multi {
        /// Target hostname or IP
        target: String,
        /// TCP ports to probe
        #[arg(long, value_delimiter = ',')]
        tcp: Vec<u16>,
        /// UDP ports to probe
        #[arg(long, value_delimiter = ',')]
        udp: Vec<u16>,
        /// Include ICMP ping
        #[arg(long)]
        icmp: bool,
        /// Timeout in seconds
        #[arg(short, long, default_value = "5")]
        timeout: u64,
    },

    /// Latency statistics (multiple samples)
    Latency {
        /// Target hostname or IP
        target: String,
        /// Port to probe
        port: u16,
        /// Number of samples
        #[arg(short, long, default_value = "20")]
        samples: usize,
        /// Interval between samples in milliseconds
        #[arg(short, long, default_value = "100")]
        interval: u64,
    },

    /// Path MTU discovery (requires elevated privileges)
    Mtu {
        /// Target hostname or IP
        target: String,
        /// Minimum MTU to test
        #[arg(long, default_value = "68")]
        min: u16,
        /// Maximum MTU to test
        #[arg(long, default_value = "1500")]
        max: u16,
        /// Timeout per probe in seconds
        #[arg(short, long, default_value = "2")]
        timeout: u64,
    },

    /// Bufferbloat detection
    Bufferbloat {
        /// Target hostname or IP
        target: String,
        /// Port to probe
        #[arg(short, long, default_value = "443")]
        port: u16,
        /// Baseline samples
        #[arg(long, default_value = "10")]
        baseline: usize,
        /// Loaded samples
        #[arg(long, default_value = "10")]
        loaded: usize,
    },

    /// Bidirectional path probing (requires multiprobe server on target)
    Bidirectional {
        /// Target hostname or IP (must be running multiprobe server)
        target: String,
        /// Port (default 33435)
        #[arg(short, long, default_value = "33435")]
        port: u16,
        /// Number of probes
        #[arg(short = 'c', long, default_value = "20")]
        count: u32,
        /// Interval between probes in milliseconds
        #[arg(short, long, default_value = "100")]
        interval: u64,
    },

    /// Start bidirectional probe server
    Server {
        /// Address to bind (default 0.0.0.0:33435)
        #[arg(short, long, default_value = "0.0.0.0:33435")]
        bind: String,
    },
}

#[tokio::main]
async fn main() {
    let cli = Cli::parse();

    let result = run_command(&cli).await;

    if let Err(e) = result {
        eprintln!("Error: {e}");
        std::process::exit(1);
    }
}

async fn run_command(cli: &Cli) -> Result<(), multiprobe::Error> {
    match &cli.command {
        Commands::Tcp { target, port, timeout } => {
            let result = Probe::tcp(target, *port)
                .timeout(Duration::from_secs(*timeout))
                .send()
                .await?;

            println!("TCP Probe: {}:{}", target, port);
            println!("  Success:  {}", result.success);
            println!("  IP:       {}", result.resolved_ip);
            println!("  Latency:  {:.2}ms", result.timing.total_ms());
            if let Some(dns) = result.timing.dns_time {
                println!("  DNS:      {:.2}ms", dns.as_secs_f64() * 1000.0);
            }
            println!("  Connect:  {:.2}ms", result.timing.connect_time.as_secs_f64() * 1000.0);
        }

        Commands::Udp { target, port, timeout } => {
            let result = Probe::udp(target, *port)
                .timeout(Duration::from_secs(*timeout))
                .send()
                .await?;

            println!("UDP Probe: {}:{}", target, port);
            println!("  Success:  {}", result.success);
            println!("  IP:       {}", result.resolved_ip);
            println!("  Latency:  {:.2}ms", result.timing.total_ms());
        }

        Commands::Icmp { target, timeout, ttl } => {
            let mut probe = Probe::icmp(target)
                .timeout(Duration::from_secs(*timeout));

            if let Some(t) = ttl {
                probe = probe.ttl(*t);
            }

            let result = probe.send().await?;

            println!("ICMP Ping: {}", target);
            println!("  Success:  {}", result.success);
            println!("  IP:       {}", result.resolved_ip);
            println!("  Latency:  {:.2}ms", result.timing.total_ms());
        }

        Commands::Tls { target, port, timeout, skip_verify } => {
            let mut probe = Probe::tls(target)
                .port(*port)
                .timeout(Duration::from_secs(*timeout));

            if *skip_verify {
                probe = probe.skip_verify();
            }

            let result = probe.send().await?;

            println!("TLS Probe: {}:{}", target, port);
            println!("  Success:    {}", result.success);
            println!("  Version:    {}", result.tls_version);
            if let Some(cipher) = &result.cipher_suite {
                println!("  Cipher:     {}", cipher);
            }
            println!("  HTTP/2:     {}", result.supports_http2());
            println!("  Modern TLS: {}", result.is_modern_tls());
            println!("\nTiming:");
            println!("  DNS:   {:.2}ms", result.timing.dns_ms());
            println!("  TCP:   {:.2}ms", result.timing.tcp_ms());
            println!("  TLS:   {:.2}ms", result.timing.tls_ms());
            println!("  Total: {:.2}ms", result.timing.total_ms());
        }

        Commands::Traceroute { target, max_hops, timeout } => {
            let result = Probe::traceroute(target)
                .max_hops(*max_hops)
                .timeout_per_hop(Duration::from_secs(*timeout))
                .send()
                .await?;

            println!("Traceroute: {} ({})", target, result.target_ip);
            println!("Reached: {}\n", result.reached_destination);

            for hop in &result.hops {
                let addr = hop.addr.map(|a| a.to_string()).unwrap_or_else(|| "*".to_string());
                let rtt = hop.rtt.as_secs_f64() * 1000.0;
                println!("{:2}. {:15} {:.2}ms", hop.ttl, addr, rtt);
            }
        }

        Commands::Paris { target, max_hops, timeout, mode, detect_lb } => {
            let paris_mode = match mode.to_lowercase().as_str() {
                "udp" => ParisMode::Udp,
                "icmp" => ParisMode::Icmp,
                "tcp" => ParisMode::Tcp,
                _ => ParisMode::Udp,
            };

            let result = Probe::paris(target)
                .max_hops(*max_hops)
                .timeout_per_hop(Duration::from_secs(*timeout))
                .mode(paris_mode)
                .detect_load_balancing(*detect_lb)
                .send()
                .await?;

            println!("Paris Traceroute: {} ({})", target, result.target_ip);
            println!("Mode: {:?}", paris_mode);
            println!("Reached: {}", result.reached_destination);
            println!("Load Balancing: {}\n", result.load_balancing);

            for hop in &result.hops {
                let addr = hop.addr.map(|a| a.to_string()).unwrap_or_else(|| "*".to_string());
                let rtt = hop.rtt.as_secs_f64() * 1000.0;
                println!("{:2}. {:15} {:.2}ms", hop.ttl, addr, rtt);
            }
        }

        Commands::Multi { target, tcp, udp, icmp, timeout } => {
            let mut probe = Probe::multi(target)
                .timeout(Duration::from_secs(*timeout));

            for port in tcp {
                probe = probe.tcp(*port);
            }
            for port in udp {
                probe = probe.udp(*port);
            }
            if *icmp {
                probe = probe.icmp();
            }

            if tcp.is_empty() && udp.is_empty() && !*icmp {
                eprintln!("Error: Specify at least one protocol (--tcp, --udp, or --icmp)");
                std::process::exit(1);
            }

            let result = probe.send().await?;

            println!("Multi-Protocol Probe: {}", target);
            println!("Classification: {}\n", result.classify());

            for r in &result.results {
                let status = if r.success { "OK" } else { "FAIL" };
                println!("  {:8} {:6} {:.2}ms", r.protocol, status, r.timing.total_ms());
            }

            if result.results.len() >= 2 {
                let pds = Classifier::differential_score(&result.results);
                println!("\nProtocol Differential Score:");
                println!("  Consistency: {:.2}", pds.consistency);
                println!("  Behavior:    {}", pds.interpret());
            }
        }

        Commands::Latency { target, port, samples, interval } => {
            let result = Probe::latency(target, *port)
                .samples(*samples)
                .interval(Duration::from_millis(*interval))
                .send()
                .await?;

            println!("Latency Statistics: {}:{}", target, port);
            println!("  Samples:  {}/{}", result.success_count, result.sample_count);
            println!("  Loss:     {:.1}%", result.loss_rate * 100.0);
            println!();
            println!("  Min:      {:.2}ms", result.min_rtt.as_secs_f64() * 1000.0);
            println!("  Max:      {:.2}ms", result.max_rtt.as_secs_f64() * 1000.0);
            println!("  Mean:     {:.2}ms", result.mean_rtt.as_secs_f64() * 1000.0);
            println!("  Median:   {:.2}ms", result.median_rtt.as_secs_f64() * 1000.0);
            println!("  P95:      {:.2}ms", result.p95_rtt.as_secs_f64() * 1000.0);
            println!("  P99:      {:.2}ms", result.p99_rtt.as_secs_f64() * 1000.0);
            println!("  Jitter:   {:.2}ms", result.jitter.as_secs_f64() * 1000.0);
            println!("  StdDev:   {:.2}ms", result.std_dev.as_secs_f64() * 1000.0);

            if result.has_high_jitter() {
                println!("\n  WARNING: High jitter detected!");
            }
            if result.has_packet_loss() {
                println!("  WARNING: Packet loss detected!");
            }
        }

        Commands::Mtu { target, min, max, timeout } => {
            let result = Probe::mtu(target)
                .min_mtu(*min)
                .max_mtu(*max)
                .timeout(Duration::from_secs(*timeout))
                .send()
                .await?;

            println!("Path MTU Discovery: {}", target);
            println!("  Path MTU:       {} bytes", result.path_mtu);
            println!("  DF Honored:     {}", result.df_honored);
            println!("  Frag Needed:    {} messages", result.frag_needed_count);
        }

        Commands::Bufferbloat { target, port, baseline, loaded } => {
            let result = Probe::bufferbloat(target)
                .port(*port)
                .baseline_samples(*baseline)
                .loaded_samples(*loaded)
                .send()
                .await?;

            println!("Bufferbloat Detection: {}:{}", target, port);
            println!("  Baseline:     {:.2}ms", result.baseline_latency.as_secs_f64() * 1000.0);
            println!("  Under Load:   {:.2}ms", result.loaded_latency.as_secs_f64() * 1000.0);
            println!("  Bloat Factor: {:.2}x", result.bloat_factor);
            println!("  Grade:        {}", result.grade);
            println!("  Detected:     {}", result.detected);
        }

        Commands::Bidirectional { target, port, count, interval } => {
            let result = Probe::bidirectional(target)
                .port(*port)
                .probe_count(*count)
                .interval(Duration::from_millis(*interval))
                .send()
                .await?;

            println!("Bidirectional Path Analysis: {}:{}", target, port);
            println!();
            println!("Forward Path (client -> server):");
            println!("  Sent:     {}", result.forward.sent);
            println!("  Received: {}", result.forward.received);
            println!("  Loss:     {:.1}%", result.forward.loss_percent());
            let fwd_min = if result.forward.min_ms == f64::MAX { 0.0 } else { result.forward.min_ms };
            println!("  Min:      {:.2}ms", fwd_min);
            println!("  Max:      {:.2}ms", result.forward.max_ms);
            println!("  Mean:     {:.2}ms", result.forward.mean_ms);
            println!("  Jitter:   {:.2}ms", result.forward.jitter_ms);
            println!();
            println!("Reverse Path (server -> client):");
            println!("  Sent:     {}", result.reverse.sent);
            println!("  Received: {}", result.reverse.received);
            println!("  Loss:     {:.1}%", result.reverse.loss_percent());
            let rev_min = if result.reverse.min_ms == f64::MAX { 0.0 } else { result.reverse.min_ms };
            println!("  Min:      {:.2}ms", rev_min);
            println!("  Max:      {:.2}ms", result.reverse.max_ms);
            println!("  Mean:     {:.2}ms", result.reverse.mean_ms);
            println!("  Jitter:   {:.2}ms", result.reverse.jitter_ms);
            println!();
            println!("Round Trip:");
            println!("  Mean:     {:.2}ms", result.round_trip.mean_ms);
            println!();
            println!("Asymmetry:");
            println!("  Score:    {:.2}", result.asymmetry_score);
            println!("  Status:   {}", result.interpretation());

            if result.asymmetric {
                println!("\n  WARNING: Significant path asymmetry detected!");
            }
        }

        Commands::Server { bind } => {
            println!("Starting multiprobe bidirectional server on {}...", bind);
            println!("Press Ctrl+C to stop.\n");

            let server = BidirectionalServer::bind(bind).await?;
            let addr = server.local_addr()?;
            println!("Listening on {}", addr);

            tokio::select! {
                result = server.run() => {
                    result?;
                }
                _ = tokio::signal::ctrl_c() => {
                    println!("\nShutting down...");
                    server.stop();
                }
            }

            println!("Server stopped. Handled {} probes.", server.probes_handled());
        }
    }

    Ok(())
}