コード例 #1
0
        public static bool StartServer()
        {
            Config     config    = SettingManager.Configuration;
            List <int> portInUse = NetworkUtil.GetPortInUse(2000);

            // proxy port
            if (config.SystemProxyPort == 0 || portInUse.Contains(config.SystemProxyPort))
            {
                config.SystemProxyPort = NetworkUtil.GetAvailablePort(2000, portInUse);
                portInUse.Add(config.SystemProxyPort);
            }
            else
            {
                portInUse.Add(config.SystemProxyPort);
            }

            // shadowsocks port
            if (config.LocalSocks5Port == 0 || portInUse.Contains(config.LocalSocks5Port))
            {
                config.LocalSocks5Port = NetworkUtil.GetAvailablePort(2000, portInUse);
                portInUse.Add(config.LocalSocks5Port);
            }
            else
            {
                portInUse.Add(config.LocalSocks5Port);
            }

            if (!ProcPrivoxy.Start(config.SystemProxyPort, config.LocalSocks5Port))
            {
                return(false);
            }

            if (SettingManager.RemoteServer != null)
            {
                return(ServerManager.AddProcess(SettingManager.RemoteServer, config.LocalSocks5Port));
            }

            return(true);
        }
コード例 #2
0
 public static void StopServer()
 {
     ProcPrivoxy.Stop();
     ServerManager.RemoveProcess(SettingManager.RemoteServer);
 }