summaryrefslogtreecommitdiffhomepage
path: root/mullvad-leak-checker/examples/leaker-cli.rs
blob: 5ef6588b0904944ac7ad4368ebed78ab174985c5 (plain)
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
use clap::{Parser, Subcommand};
use mullvad_leak_checker::traceroute::TracerouteOpt;

#[derive(Parser)]
pub struct Opt {
    #[clap(subcommand)]
    pub method: LeakMethod,
}

#[derive(Subcommand, Clone)]
pub enum LeakMethod {
    /// Check for leaks by binding to a non-tunnel interface and probing for reachable nodes.
    Traceroute(#[clap(flatten)] TracerouteOpt),

    /// Ask `am.i.mullvad.net` whether you are leaking.
    #[cfg(feature = "am-i-mullvad")]
    AmIMullvad(#[clap(flatten)] mullvad_leak_checker::am_i_mullvad::AmIMullvadOpt),
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    env_logger::builder()
        .filter_level(log::LevelFilter::Debug)
        .parse_default_env()
        .init();

    let opt = Opt::parse();

    let leak_status = match &opt.method {
        LeakMethod::Traceroute(opt) => mullvad_leak_checker::traceroute::run_leak_test(opt).await,
        #[cfg(feature = "am-i-mullvad")]
        LeakMethod::AmIMullvad(opt) => mullvad_leak_checker::am_i_mullvad::run_leak_test(opt).await,
    };

    log::info!("Leak status: {leak_status:#?}");

    Ok(())
}