2023-03-22 11:17:28 +01:00
|
|
|
use clap::Parser;
|
2022-08-16 16:18:25 +02:00
|
|
|
use env_logger::Env;
|
2023-03-22 01:02:27 +01:00
|
|
|
|
2023-03-23 13:03:01 +01:00
|
|
|
use tun2proxy::tun2proxy::Options;
|
2023-03-22 13:18:07 +01:00
|
|
|
use tun2proxy::{main_entry, Proxy};
|
2023-03-20 14:13:06 +08:00
|
|
|
|
|
|
|
/// Tunnel interface to proxy
|
|
|
|
#[derive(Parser)]
|
|
|
|
#[command(author, version, about = "Tunnel interface to proxy.", long_about = None)]
|
|
|
|
struct Args {
|
|
|
|
/// Name of the tun interface
|
2023-03-22 11:17:28 +01:00
|
|
|
#[arg(short, long, value_name = "name", default_value = "tun0")]
|
2023-03-20 14:13:06 +08:00
|
|
|
tun: String,
|
|
|
|
|
2023-03-22 12:08:07 +01:00
|
|
|
/// The proxy URL in the form proto://[username[:password]@]host:port
|
2023-03-22 13:18:07 +01:00
|
|
|
#[arg(short, long = "proxy", value_parser = Proxy::from_url, value_name = "URL")]
|
|
|
|
proxy: Proxy,
|
2023-03-23 13:03:01 +01:00
|
|
|
|
|
|
|
#[arg(short, long = "dns")]
|
|
|
|
virtual_dns: bool,
|
2023-03-22 11:17:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
let addr = args.proxy.addr;
|
2023-03-22 12:18:41 +01:00
|
|
|
let proxy_type = args.proxy.proxy_type;
|
|
|
|
log::info!("Proxy {proxy_type} server: {addr}");
|
|
|
|
|
2023-03-23 13:03:01 +01:00
|
|
|
let mut options = Options::new();
|
|
|
|
if args.virtual_dns {
|
|
|
|
options = options.with_virtual_dns();
|
|
|
|
}
|
|
|
|
|
|
|
|
main_entry(&args.tun, args.proxy, options);
|
2021-09-02 11:30:23 +02:00
|
|
|
}
|