2023-03-21 00:11:51 +08:00
|
|
|
use tun2proxy::{ProxyType, main_entry};
|
2023-03-20 14:13:06 +08:00
|
|
|
use clap::{Parser, ValueEnum};
|
2022-08-16 16:18:25 +02:00
|
|
|
use env_logger::Env;
|
2023-03-20 14:13:06 +08:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
|
|
/// 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-20 17:27:28 +08:00
|
|
|
#[arg(short, long, value_name = "name")]
|
2023-03-20 14:13:06 +08:00
|
|
|
tun: String,
|
|
|
|
|
|
|
|
/// What proxy type to run
|
2023-03-20 17:27:28 +08:00
|
|
|
#[arg(short, long = "proxy", value_name = "type", value_enum)]
|
2023-03-20 17:52:15 +08:00
|
|
|
proxy_type: ArgProxyType,
|
2023-03-20 14:13:06 +08:00
|
|
|
|
2023-03-20 17:27:28 +08:00
|
|
|
/// Server address with format ip:port
|
|
|
|
#[clap(short, long, value_name = "ip:port")]
|
2023-03-20 14:13:06 +08:00
|
|
|
addr: SocketAddr,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
2023-03-20 17:52:15 +08:00
|
|
|
enum ArgProxyType {
|
2023-03-20 14:13:06 +08:00
|
|
|
/// SOCKS5 server to use
|
|
|
|
Socks5,
|
|
|
|
/// HTTP server to use
|
|
|
|
Http,
|
|
|
|
}
|
2021-09-02 11:30:23 +02:00
|
|
|
|
|
|
|
fn main() {
|
2022-08-16 16:18:25 +02:00
|
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
2023-03-20 14:13:06 +08:00
|
|
|
let args = Args::parse();
|
2021-09-02 11:30:23 +02:00
|
|
|
|
2023-03-20 14:13:06 +08:00
|
|
|
match args.proxy_type {
|
2023-03-20 17:52:15 +08:00
|
|
|
ArgProxyType::Socks5 => {
|
2023-03-20 14:13:06 +08:00
|
|
|
log::info!("SOCKS5 server: {}", args.addr);
|
2023-03-21 00:11:51 +08:00
|
|
|
main_entry(&args.tun, args.addr, ProxyType::Socks5);
|
2021-09-02 11:30:23 +02:00
|
|
|
}
|
2023-03-20 17:52:15 +08:00
|
|
|
ArgProxyType::Http => {
|
2023-03-20 14:13:06 +08:00
|
|
|
log::info!("HTTP server: {}", args.addr);
|
2023-03-21 00:11:51 +08:00
|
|
|
main_entry(&args.tun, args.addr, ProxyType::Http);
|
2021-09-02 11:30:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|