Esempio n. 1
0
 static Flags()
 {
     Task.Run(() => {
         SupportFakeDns   = new TUNTAPController().TestFakeDNS();
         IsWindows10Upper = Environment.OSVersion.Version.Major >= 10;
     });
 }
Esempio n. 2
0
 private static void AutoSearchTapAdapter()
 {
     if (Global.TUNTAP.Adapter == null)
     {
         TUNTAPController.SearchTapAdapter();
     }
 }
Esempio n. 3
0
        public static IModeController GetModeControllerByType(int type, out ushort?port, out string portName, out PortType portType)
        {
            IModeController modeController;

            port     = null;
            portName = string.Empty;
            portType = PortType.Both;
            switch (type)
            {
            case 0:
                modeController = new NFController();
                port           = Global.Settings.RedirectorTCPPort;
                portName       = "Redirector TCP";
                break;

            case 1:
            case 2:
                modeController = new TUNTAPController();
                break;

            case 3:
            case 5:
                modeController = new HTTPController();
                port           = Global.Settings.HTTPLocalPort;
                portName       = "HTTP";
                MainForm.StatusPortInfoText.HttpPort = (ushort)port;
                break;

            default:
                Logging.Error("未知模式类型");
                throw new StartFailedException();
            }

            return(modeController);
        }
Esempio n. 4
0
        private void InitValue()
        {
            // Local Port
            Socks5PortTextBox.Text       = Global.Settings.Socks5LocalPort.ToString();
            HTTPPortTextBox.Text         = Global.Settings.HTTPLocalPort.ToString();
            RedirectorTextBox.Text       = Global.Settings.RedirectorTCPPort.ToString();
            AllowDevicesCheckBox.Checked = Global.Settings.LocalAddress switch
            {
                "127.0.0.1" => false,
                "0.0.0.0" => true,
                _ => false
            };

            // TUN/TAP
            TUNTAPAddressTextBox.Text    = Global.Settings.TUNTAP.Address;
            TUNTAPNetmaskTextBox.Text    = Global.Settings.TUNTAP.Netmask;
            TUNTAPGatewayTextBox.Text    = Global.Settings.TUNTAP.Gateway;
            UseCustomDNSCheckBox.Checked = Global.Settings.TUNTAP.UseCustomDNS;
            TUNTAPUseCustomDNSCheckBox_CheckedChanged(null, null);
            ProxyDNSCheckBox.Checked   = Global.Settings.TUNTAP.ProxyDNS;
            UseFakeDNSCheckBox.Checked = Global.Settings.TUNTAP.UseFakeDNS;

            if (TUNTAPController.SearchTapAdapter())
            {
                ICSCheckBox.Enabled = true;
                ICSCheckBox.Checked = ICSHelper.Enabled;
            }

            // Behavior
            ExitWhenClosedCheckBox.Checked              = Global.Settings.ExitWhenClosed;
            StopWhenExitedCheckBox.Checked              = Global.Settings.StopWhenExited;
            StartWhenOpenedCheckBox.Checked             = Global.Settings.StartWhenOpened;
            MinimizeWhenStartedCheckBox.Checked         = Global.Settings.MinimizeWhenStarted;
            RunAtStartupCheckBox.Checked                = Global.Settings.RunAtStartup;
            CheckUpdateWhenOpenedCheckBox.Checked       = Global.Settings.CheckUpdateWhenOpened;
            BootShadowsocksFromDLLCheckBox.Checked      = Global.Settings.BootShadowsocksFromDLL;
            CheckBetaUpdateCheckBox.Checked             = Global.Settings.CheckBetaUpdate;
            ModifySystemDNSCheckBox.Checked             = Global.Settings.ModifySystemDNS;
            UpdateSubscribeatWhenOpenedCheckBox.Checked = Global.Settings.UpdateSubscribeatWhenOpened;

            ProfileCountTextBox.Text        = Global.Settings.ProfileCount.ToString();
            TcpingAtStartedCheckBox.Checked = Global.Settings.StartedTcping;
            DetectionIntervalTextBox.Text   = Global.Settings.StartedTcping_Interval.ToString();
            InitSTUN();
            AclAddrTextBox.Text = Global.Settings.ACL;
            LanguageComboBox.Items.AddRange(i18N.GetTranslateList().ToArray());
            LanguageComboBox.SelectedItem = Global.Settings.Language;
        }
Esempio n. 5
0
        private void lbStart_Click(object sender, EventArgs e)
        {
            panel_Menu.Visible = false;
            if (lbStart.Tag.ToInt32() == 0)//未加速状态
            {
                if (user == null)
                {
                    CCWin.MessageBoxEx.Show("请先登录账号!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (CurrentGame == null)
                {
                    CCWin.MessageBoxEx.Show("请先选择需要加速的游戏!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (shadowsocksR == null)
                {
                    new ChooseLineFrm().ShowDialog();
                    if (shadowsocksR == null)
                    {
                        return;
                    }
                    lbChooseLine.Text = shadowsocksR.Remark;
                    timer1.Enabled    = true;
                    TestLine();
                }
                KillController();
                lbStart.Text         = "请稍等...";
                lbChooseLine.Enabled = false;
                ssrController        = new SSRController(shadowsocksR);
                if (ssrController.Start())
                {
                    TUNTAPController      = new TUNTAPController();
                    lbStateText.ForeColor = Color.LimeGreen;
                    lbStateText.Text      = "正在初始化环境...";
                    Application.DoEvents();
                }
                else
                {
                    CCWin.MessageBoxEx.Show("加速失败,请重新启动!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lbStateText.ForeColor = Color.Red;
                    lbStateText.Text      = "初始化程序错误...";
                    lbStart.ForeColor     = Color.DimGray;
                    lbStart.Text          = "一键加速";
                    lbStart.Tag           = 0;
                    AddRouteList();
                    lbStateText.ForeColor = Color.Red;
                    lbStateText.Text      = "初始化程序错误...";
                    btnAddGame.Enabled    = true;
                    lbChooseGame.Enabled  = true;
                    lbChooseLine.Enabled  = true;
                    return;
                }

                if (TUNTAPController.Start())
                {
                    AddRouteList();
                    lbStart.ForeColor    = Color.Red;
                    lbStart.Text         = "断开连接";
                    lbStart.Tag          = 1;
                    timer2.Enabled       = true;
                    lbStateText.Text     = "已成功连接线路";
                    btnAddGame.Enabled   = false;
                    lbChooseGame.Enabled = false;
                }
                else
                {
                    lbStart.ForeColor = Color.DimGray;
                    lbStart.Text      = "一键加速";
                    lbStart.Tag       = 0;
                    AddRouteList();
                    lbStateText.ForeColor = Color.Red;
                    lbStateText.Text      = "初始化程序错误...";
                    btnAddGame.Enabled    = true;
                    lbChooseGame.Enabled  = true;
                    lbChooseLine.Enabled  = true;
                }
            }
            else if (lbStart.Tag.ToInt32() == 1)
            {
                timer2.Enabled = false;
                KillController();
                TUNTAPController.CreatDelRoute();

                lbStart.ForeColor = Color.DimGray;
                lbStart.Text      = "一键加速";
                lbStart.Tag       = 0;
                lbStateText.Text  = "断开连接成功";
                AddRouteList();
                btnAddGame.Enabled   = true;
                lbChooseGame.Enabled = true;
                lbChooseLine.Enabled = true;
            }
        }
Esempio n. 6
0
        public static bool Enable()
        {
            Utils.SearchOutboundAdapter();
            TUNTAPController.SearchTapAdapter();

            if (Global.TUNTAP.Adapter == null || Global.Outbound.Adapter == null)
            {
                return(false);
            }

            try
            {
                CleanupWMISharingEntries();

                #region Save Outbound IP Config

                bool     dhcpEnabled;
                string[] ipAddress     = null;
                string[] subnetMask    = null;
                string[] gateway       = null;
                ushort[] gatewayMetric = null;
                string[] dns           = null;

                var outboundWmi = GetManagementObjectByDeviceNameOrDefault(Global.Outbound.Adapter.Description);

                if (outboundWmi == null)
                {
                    return(false);
                }

                if (!(dhcpEnabled = (bool)outboundWmi["DHCPEnabled"]))
                {
                    ipAddress     = (string[])outboundWmi["IPAddress"];
                    subnetMask    = (string[])outboundWmi["IPSubnet"];
                    gateway       = (string[])outboundWmi["DefaultIPGateway"];
                    gatewayMetric = (ushort[])outboundWmi["GatewayCostMetric"];
                    dns           = (string[])outboundWmi["DNSServerSearchOrder"];

                    ipAddress  = new[] { ipAddress[0] };
                    subnetMask = new[] { subnetMask[0] };
                }

                #endregion

                #region Setting ICS

                foreach (NetworkConnection connection in new NetworkConnectionCollection())
                {
                    if (connection.DeviceName == Global.TUNTAP.Adapter.Description)
                    {
                        if (connection.SharingEnabled)
                        {
                            connection.DisableSharing();
                        }
                        connection.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC);
                    }
                    else if (connection.DeviceName == Global.Outbound.Adapter.Description)
                    {
                        if (connection.SharingEnabled)
                        {
                            connection.DisableSharing();
                        }
                        connection.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE);
                    }
                }

                #endregion

                #region Reset Outbound IP Config

                if (dhcpEnabled)
                {
                    outboundWmi.InvokeMethod("EnableDHCP", null, null);
                }
                else
                {
                    //Set static IP and subnet mask
                    var ip = outboundWmi.GetMethodParameters("EnableStatic");
                    ip["IPAddress"]  = ipAddress;
                    ip["SubnetMask"] = subnetMask;
                    outboundWmi.InvokeMethod("EnableStatic", ip, null);
                    //Set default gateway
                    var newGateway = outboundWmi.GetMethodParameters("SetGateways");
                    newGateway["DefaultIPGateway"]  = gateway;
                    newGateway["GatewayCostMetric"] = gatewayMetric;
                    outboundWmi.InvokeMethod("SetGateways", newGateway, null);
                    //Set dns servers
                    var newDns = outboundWmi.GetMethodParameters("SetDNSServerSearchOrder");
                    newDns["DNSServerSearchOrder"] = dns;
                    outboundWmi.InvokeMethod("SetDNSServerSearchOrder", newDns, null);
                }

                #endregion

                return(true);
            }
            catch (Exception e)
            {
                try
                {
                    Disable();
                }
                catch
                {
                    // ignored
                }

                Logging.Error($"网络连接共享设置失败: {e}");

                return(false);
            }
        }