예제 #1
0
        private IServer ParseSSProtocol(string protocol)
        {
            Regex regex = new Regex(@"^(.+?):(.+?)@(.+?):((?:[0-9]{1}|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])+?)$");

            var match = regex.Match(protocol);

            if (!match.Success)
            {
                AppLogProxy.AppLog.WriteLog <SubscribeUpdater>(string.Format("该SS订阅信息无法解析, Protocol: {0}", protocol));
                return(null);
            }

            string algorithm = match.Groups[1].Value;
            string password  = match.Groups[2].Value;
            string host      = match.Groups[3].Value;
            int    port      = Convert.ToInt32(match.Groups[4].Value);

            if (!EncryptionCenter.IsSupport(algorithm))
            {
                AppLogProxy.AppLog.WriteLog <SubscribeUpdater>(string.Format("该SS加密方案无法支持, Protocol: {0}", protocol));
                return(null);
            }

            ShadowsockServer server = new ShadowsockServer();

            server.Protocol.Name = "origin";
            server.Algorithm     = algorithm;
            server.Host          = host;
            server.Port          = port;

            return(server);
        }