tun2proxy/src/main.rs

55 lines
1.3 KiB
Rust
Raw Normal View History

2021-09-02 11:30:23 +02:00
mod http;
2022-08-01 14:36:58 +00:00
mod socks5;
2021-09-02 11:30:23 +02:00
mod tun2proxy;
2022-08-01 14:36:58 +00:00
mod virtdevice;
2021-09-02 11:30:23 +02:00
use crate::http::HttpManager;
use crate::tun2proxy::TunToProxy;
2023-03-20 14:13:06 +08:00
use clap::{Parser, ValueEnum};
2022-08-16 16:18:25 +02:00
use env_logger::Env;
2022-08-01 14:36:58 +00:00
use socks5::*;
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
#[arg(short, long)]
tun: String,
/// What proxy type to run
#[arg(short, long = "proxy", value_enum)]
proxy_type: ProxyType,
/// Server address with format IP:PORT
#[clap(short, long)]
addr: SocketAddr,
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum ProxyType {
/// 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
let mut ttp = TunToProxy::new(&args.tun);
match args.proxy_type {
ProxyType::Socks5 => {
log::info!("SOCKS5 server: {}", args.addr);
ttp.add_connection_manager(Box::new(Socks5Manager::new(args.addr)));
2021-09-02 11:30:23 +02:00
}
2023-03-20 14:13:06 +08:00
ProxyType::Http => {
log::info!("HTTP server: {}", args.addr);
ttp.add_connection_manager(Box::new(HttpManager::new(args.addr)));
2021-09-02 11:30:23 +02:00
}
}
ttp.run();
}