using Shadowsocks.Protocol; using System; using System.CommandLine; using System.CommandLine.Invocation; using System.Net; using System.Text; using System.Threading.Tasks; namespace Shadowsocks.CLI { internal class Program { private static Task Main(string[] args) { var clientCommand = new Command("client", "Shadowsocks client."); clientCommand.AddAlias("c"); clientCommand.AddOption(new Option("--listen", "The address and port to listen on for both SOCKS5 and HTTP proxy.")); clientCommand.AddOption(new Option("--listen-socks", "The address and port to listen on for SOCKS5 proxy.")); clientCommand.AddOption(new Option("--listen-http", "The address and port to listen on for HTTP proxy.")); clientCommand.AddOption(new Option("--server-address", "Address of the remote Shadowsocks server to connect to.")); clientCommand.AddOption(new Option("--server-port", "Port of the remote Shadowsocks server to connect to.")); clientCommand.AddOption(new Option("--method", "Encryption method to use for the remote Shadowsocks server.")); clientCommand.AddOption(new Option("--password", "Password to use for the remote Shadowsocks server.")); clientCommand.AddOption(new Option("--key", "Encryption key (NOT password!) to use for the remote Shadowsocks server.")); clientCommand.AddOption(new Option("--plugin", "Plugin binary path.")); clientCommand.AddOption(new Option("--plugin-opts", "Plugin options.")); clientCommand.AddOption(new Option("--plugin-args", "Plugin startup arguments.")); clientCommand.Handler = CommandHandler.Create( async (string? listen, string? listenSocks, string? listenHttp, string serverAddress, int serverPort, string method, string? password, string? key, string? plugin, string? pluginOpts, string? pluginArgs) => { // TODO var localEP = IPEndPoint.Parse(listenSocks); var remoteEp = new DnsEndPoint(serverAddress, serverPort); byte[]? mainKey = null; if (!string.IsNullOrEmpty(key)) mainKey = Encoding.UTF8.GetBytes(key); var tcpPipeListener = new TcpPipeListener(localEP); tcpPipeListener.Start(localEP, remoteEp, method, password, mainKey).Wait(); }); var serverCommand = new Command("server", "Shadowsocks server."); serverCommand.AddAlias("s"); serverCommand.Handler = CommandHandler.Create( () => { Console.WriteLine("Not implemented."); }); var utilitiesCommand = new Command("utilities", "Shadowsocks-related utilities."); utilitiesCommand.AddAlias("u"); utilitiesCommand.AddAlias("util"); utilitiesCommand.AddAlias("utils"); var rootCommand = new RootCommand("CLI for Shadowsocks server and client implementation in C#.") { clientCommand, serverCommand, utilitiesCommand, }; Console.OutputEncoding = Encoding.UTF8; return rootCommand.InvokeAsync(args); } } }