Skip to content

Commit

Permalink
feat: Resolve Server hostname option
Browse files Browse the repository at this point in the history
  • Loading branch information
chsbuffer committed Oct 10, 2020
1 parent 0222792 commit 12b2989
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Netch/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static async Task<bool> Start(Server server, Mode mode)
return false;
}

if (DNS.Lookup(server.Hostname) == null)
if (Global.Settings.ResolveServerHostname && DNS.Lookup(server.Hostname) == null)
{
MessageBoxX.Show("Lookup Server hostname failed");
return false;
Expand Down
54 changes: 34 additions & 20 deletions Netch/Forms/SettingForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Netch/Forms/SettingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private void InitValue()
CheckBetaUpdateCheckBox.Checked = Global.Settings.CheckBetaUpdate;
ModifySystemDNSCheckBox.Checked = Global.Settings.ModifySystemDNS;
UpdateSubscribeatWhenOpenedCheckBox.Checked = Global.Settings.UpdateSubscribeatWhenOpened;
ResolveServerHostnameCheckBox.Checked = Global.Settings.ResolveServerHostname;

ProfileCountTextBox.Text = Global.Settings.ProfileCount.ToString();
TcpingAtStartedCheckBox.Checked = Global.Settings.StartedTcping;
Expand Down Expand Up @@ -329,6 +330,7 @@ static void CheckPort(string portName, int port, int originPort, PortType portTy
Global.Settings.CheckBetaUpdate = CheckBetaUpdateCheckBox.Checked;
Global.Settings.ModifySystemDNS = ModifySystemDNSCheckBox.Checked;
Global.Settings.UpdateSubscribeatWhenOpened = UpdateSubscribeatWhenOpenedCheckBox.Checked;
Global.Settings.ResolveServerHostname = ResolveServerHostnameCheckBox.Checked;

Global.Settings.ProfileCount = profileCount;
Global.Settings.StartedTcping = TcpingAtStartedCheckBox.Checked;
Expand Down
8 changes: 8 additions & 0 deletions Netch/Models/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ public int Test()
}
}
}

public static class ServerExtension
{
public static string AutoResolveHostname(this Server server)
{
return Global.Settings.ResolveServerHostname ? DNS.Lookup(server.Hostname).ToString() : server.Hostname;
}
}
}
5 changes: 5 additions & 0 deletions Netch/Models/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public class Setting
/// </summary>
public bool ModifySystemDNS = false;

/// <summary>
/// 解析服务器主机名
/// </summary>
public bool ResolveServerHostname = true;

/// <summary>
/// 网页请求超时 毫秒
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Netch/Resources/zh-CN
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"Custom ACL": "自定义 ACL 规则",
"Language": "语言",
"Tap Network Sharing": "Tap 网络共享",
"Resolve Server Hostname": "解析服务器主机名",

"Profile": "配置名",
"Profiles": "配置",
Expand Down
4 changes: 2 additions & 2 deletions Netch/Servers/Shadowsocks/SSController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public bool Start(Server s, Mode mode)
{
State = State.Starting;
var client = Encoding.UTF8.GetBytes($"{this.LocalAddress()}:{this.Socks5LocalPort()}");
var remote = Encoding.UTF8.GetBytes($"{DNS.Lookup(server.Hostname)}:{server.Port}");
var remote = Encoding.UTF8.GetBytes($"{server.AutoResolveHostname()}:{server.Port}");
var passwd = Encoding.UTF8.GetBytes($"{server.Password}");
var method = Encoding.UTF8.GetBytes($"{server.EncryptMethod}");
if (!ShadowsocksDLL.Info(client, remote, passwd, method))
Expand Down Expand Up @@ -55,7 +55,7 @@ public bool Start(Server s, Mode mode)

var argument = new StringBuilder();
argument.Append(
$"-s {DNS.Lookup(server.Hostname)} " +
$"-s {server.AutoResolveHostname()} " +
$"-p {server.Port} " +
$"-b {this.LocalAddress()} " +
$"-l {this.Socks5LocalPort()} " +
Expand Down
2 changes: 1 addition & 1 deletion Netch/Servers/ShadowsocksR/SSRController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public bool Start(Server s, Mode mode)
#region Argument

var argument = new StringBuilder();
argument.Append($"-s {DNS.Lookup(server.Hostname)} -p {server.Port} -k \"{server.Password}\" -m {server.EncryptMethod} -t 120");
argument.Append($"-s {server.AutoResolveHostname()} -p {server.Port} -k \"{server.Password}\" -m {server.EncryptMethod} -t 120");
if (!string.IsNullOrEmpty(server.Protocol))
{
argument.Append($" -O {server.Protocol}");
Expand Down
2 changes: 1 addition & 1 deletion Netch/Servers/Trojan/TrojanController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public bool Start(Server s, Mode mode)
{
local_addr = this.LocalAddress(),
local_port = this.Socks5LocalPort(),
remote_addr = DNS.Lookup(server.Hostname).ToString(),
remote_addr = server.AutoResolveHostname(),
remote_port = server.Port,
password = new List<string>
{
Expand Down
2 changes: 1 addition & 1 deletion Netch/Servers/VMess/VMessController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public bool Start(Server s, Mode mode)
{
new VMessConfig.VNext
{
address = DNS.Lookup(server.Hostname).ToString(),
address = server.AutoResolveHostname(),
port = server.Port,
users = new List<VMessConfig.User>
{
Expand Down

0 comments on commit 12b2989

Please sign in to comment.