built-in stun server list

This commit is contained in:
ChsBuffer
2020-08-13 12:49:47 +08:00
parent a2838b8217
commit 4116daf63c
3 changed files with 42 additions and 51 deletions

View File

@@ -61,11 +61,9 @@
this.DetectionIntervalLabel = new System.Windows.Forms.Label();
this.DetectionIntervalTextBox = new System.Windows.Forms.TextBox();
this.TcpingAtStartedCheckBox = new System.Windows.Forms.CheckBox();
this.STUN_ServerPortTextBox = new System.Windows.Forms.TextBox();
this.StunTextBoxSplitLabel = new System.Windows.Forms.Label();
this.STUNServerLabel = new System.Windows.Forms.Label();
this.RunAtStartupCheckBox = new System.Windows.Forms.CheckBox();
this.STUN_ServerTextBox = new System.Windows.Forms.TextBox();
this.STUN_ServerComboBox = new System.Windows.Forms.SearchComboBox();
this.MinimizeWhenStartedCheckBox = new System.Windows.Forms.CheckBox();
this.ProfileCountLabel = new System.Windows.Forms.Label();
this.ProfileCountTextBox = new System.Windows.Forms.TextBox();
@@ -278,7 +276,7 @@
//
// ControlButton
//
this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ControlButton.Location = new System.Drawing.Point(804, 356);
this.ControlButton.Name = "ControlButton";
this.ControlButton.Size = new System.Drawing.Size(75, 23);
@@ -289,7 +287,7 @@
//
// GlobalBypassIPsButton
//
this.GlobalBypassIPsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.GlobalBypassIPsButton.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.GlobalBypassIPsButton.Location = new System.Drawing.Point(12, 356);
this.GlobalBypassIPsButton.Name = "GlobalBypassIPsButton";
this.GlobalBypassIPsButton.Size = new System.Drawing.Size(128, 23);
@@ -309,11 +307,9 @@
this.BehaviorGroupBox.Controls.Add(this.DetectionIntervalLabel);
this.BehaviorGroupBox.Controls.Add(this.DetectionIntervalTextBox);
this.BehaviorGroupBox.Controls.Add(this.TcpingAtStartedCheckBox);
this.BehaviorGroupBox.Controls.Add(this.STUN_ServerPortTextBox);
this.BehaviorGroupBox.Controls.Add(this.StunTextBoxSplitLabel);
this.BehaviorGroupBox.Controls.Add(this.STUNServerLabel);
this.BehaviorGroupBox.Controls.Add(this.RunAtStartupCheckBox);
this.BehaviorGroupBox.Controls.Add(this.STUN_ServerTextBox);
this.BehaviorGroupBox.Controls.Add(this.STUN_ServerComboBox);
this.BehaviorGroupBox.Controls.Add(this.MinimizeWhenStartedCheckBox);
this.BehaviorGroupBox.Controls.Add(this.ProfileCountLabel);
this.BehaviorGroupBox.Controls.Add(this.ProfileCountTextBox);
@@ -412,23 +408,6 @@
this.TcpingAtStartedCheckBox.Text = "Delay test after start";
this.TcpingAtStartedCheckBox.UseVisualStyleBackColor = true;
//
// STUN_ServerPortTextBox
//
this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(366, 241);
this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox";
this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(68, 23);
this.STUN_ServerPortTextBox.TabIndex = 8;
this.STUN_ServerPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// StunTextBoxSplitLabel
//
this.StunTextBoxSplitLabel.AutoSize = true;
this.StunTextBoxSplitLabel.Location = new System.Drawing.Point(353, 244);
this.StunTextBoxSplitLabel.Name = "StunTextBoxSplitLabel";
this.StunTextBoxSplitLabel.Size = new System.Drawing.Size(11, 17);
this.StunTextBoxSplitLabel.TabIndex = 12;
this.StunTextBoxSplitLabel.Text = ":";
//
// STUNServerLabel
//
this.STUNServerLabel.AutoSize = true;
@@ -448,13 +427,13 @@
this.RunAtStartupCheckBox.Text = "Run at startup";
this.RunAtStartupCheckBox.UseVisualStyleBackColor = true;
//
// STUN_ServerTextBox
// STUN_ServerComboBox
//
this.STUN_ServerTextBox.Location = new System.Drawing.Point(120, 241);
this.STUN_ServerTextBox.Name = "STUN_ServerTextBox";
this.STUN_ServerTextBox.Size = new System.Drawing.Size(233, 23);
this.STUN_ServerTextBox.TabIndex = 11;
this.STUN_ServerTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.STUN_ServerComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.STUN_ServerComboBox.Location = new System.Drawing.Point(120, 241);
this.STUN_ServerComboBox.Name = "STUN_ServerComboBox";
this.STUN_ServerComboBox.Size = new System.Drawing.Size(314, 25);
this.STUN_ServerComboBox.TabIndex = 11;
//
// MinimizeWhenStartedCheckBox
//
@@ -548,9 +527,9 @@
this.Controls.Add(this.GlobalBypassIPsButton);
this.Controls.Add(this.ControlButton);
this.Controls.Add(this.TUNTAPGroupBox);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (134)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximizeBox = false;
this.Name = "SettingForm";
@@ -565,7 +544,6 @@
this.BehaviorGroupBox.ResumeLayout(false);
this.BehaviorGroupBox.PerformLayout();
this.ResumeLayout(false);
}
#endregion
@@ -597,10 +575,8 @@
private System.Windows.Forms.TextBox ProfileCountTextBox;
private System.Windows.Forms.CheckBox MinimizeWhenStartedCheckBox;
private System.Windows.Forms.CheckBox RunAtStartupCheckBox;
private System.Windows.Forms.Label StunTextBoxSplitLabel;
private System.Windows.Forms.Label STUNServerLabel;
private System.Windows.Forms.TextBox STUN_ServerTextBox;
private System.Windows.Forms.TextBox STUN_ServerPortTextBox;
private System.Windows.Forms.SearchComboBox STUN_ServerComboBox;
private System.Windows.Forms.CheckBox ProxyDNSCheckBox;
private System.Windows.Forms.TextBox DetectionIntervalTextBox;
private System.Windows.Forms.CheckBox TcpingAtStartedCheckBox;

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using Netch.Models;
@@ -111,11 +113,10 @@ namespace Netch.Forms
ProfileCountTextBox.Text = Global.Settings.ProfileCount.ToString();
TcpingAtStartedCheckBox.Checked = Global.Settings.StartedTcping;
DetectionIntervalTextBox.Text = Global.Settings.StartedTcping_Interval.ToString();
STUN_ServerTextBox.Text = Global.Settings.STUN_Server;
STUN_ServerPortTextBox.Text = Global.Settings.STUN_Server_Port.ToString();
AclAddrTextBox.Text = Global.Settings.ACL;
LanguageComboBox.Items.AddRange(i18N.GetTranslateList().ToArray());
LanguageComboBox.SelectedItem = Global.Settings.Language;
InitSTUN();
}
private void InitText()
@@ -146,15 +147,28 @@ namespace Netch.Forms
TcpingAtStartedCheckBox.Text = i18N.Translate(TcpingAtStartedCheckBox.Text);
DetectionIntervalLabel.Text = i18N.Translate(DetectionIntervalLabel.Text);
STUNServerLabel.Text = i18N.Translate(STUNServerLabel.Text);
StunTextBoxSplitLabel.Text = i18N.Translate(StunTextBoxSplitLabel.Text);
AclLabel.Text = i18N.Translate(AclLabel.Text);
LanguageLabel.Text = i18N.Translate(LanguageLabel.Text);
}
private void InitSTUN()
{
try
{
var stuns = File.ReadLines("bin\\stun.txt");
STUN_ServerComboBox.Items.AddRange(stuns.ToArray());
}
catch (Exception e)
{
// ignored
}
STUN_ServerComboBox.Text = $"{Global.Settings.STUN_Server}:{Global.Settings.STUN_Server_Port}";
}
private void SettingForm_Load(object sender, EventArgs e)
{
InitText();
InitValue();
}
@@ -185,8 +199,10 @@ namespace Netch.Forms
var scheduler = new TaskSchedulerClass();
scheduler.Connect();
var folder = scheduler.GetFolder("\\");
var taskIsExists = false;
try
{
folder.GetTask("Netch Startup");
taskIsExists = true;
@@ -215,8 +231,10 @@ namespace Netch.Forms
task.Settings.DisallowStartIfOnBatteries = false;
task.Settings.RunOnlyIfIdle = false;
folder.RegisterTaskDefinition("Netch Startup", task, (int) _TASK_CREATION.TASK_CREATE, null, null, _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN, "");
folder.RegisterTaskDefinition("Netch Startup", task, (int) _TASK_CREATION.TASK_CREATE, null, null,
_TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN, "");
}
else
{
if (taskIsExists)
@@ -230,9 +248,7 @@ namespace Netch.Forms
return;
if (!CheckPortText("RedirectorTCP", ref RedirectorTextBox, ref Global.Settings.RedirectorTCPPort, PortType.TCP))
return;
Global.Settings.LocalAddress = AllowDevicesCheckBox.Checked ? "0.0.0.0" : "127.0.0.1";
try
{
var Address = IPAddress.Parse(TUNTAPAddressTextBox.Text);
@@ -290,10 +306,13 @@ namespace Netch.Forms
try
{
var STUN_Server = STUN_ServerTextBox.Text;
var stun = STUN_ServerComboBox.Text.Split(':');
var STUN_Server = stun[0];
Global.Settings.STUN_Server = STUN_Server;
var STUN_ServerPort = int.Parse(STUN_ServerPortTextBox.Text);
var STUN_ServerPort = 3478;
if (stun.Length > 1)
STUN_ServerPort = int.Parse(stun[1]);
if (STUN_ServerPort > 0)
{
@@ -336,11 +355,9 @@ namespace Netch.Forms
}
Global.Settings.ACL = AclAddrTextBox.Text;
Global.Settings.TUNTAP.Address = TUNTAPAddressTextBox.Text;
Global.Settings.TUNTAP.Netmask = TUNTAPNetmaskTextBox.Text;
Global.Settings.TUNTAP.Gateway = TUNTAPGatewayTextBox.Text;
Global.Settings.TUNTAP.DNS.Clear();
foreach (var ip in TUNTAPDNSTextBox.Text.Split(','))
{
@@ -350,9 +367,7 @@ namespace Netch.Forms
Global.Settings.TUNTAP.UseCustomDNS = UseCustomDNSCheckBox.Checked;
Global.Settings.TUNTAP.ProxyDNS = ProxyDNSCheckBox.Checked;
Global.Settings.TUNTAP.UseFakeDNS = UseFakeDNSCheckBox.Checked;
Global.Settings.ModifySystemDNS = ModifySystemDNSCheckBox.Checked;
Configuration.Save();
MessageBoxX.Show(i18N.Translate("Saved"));
Close();