From 176d1020004d55d9b6859a46b7f1721bd7e0ab4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=9B=BD=E5=88=9A?= <65169947@163.com> Date: Thu, 26 Nov 2020 16:17:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E5=A4=9A=E7=BD=91?= =?UTF-8?q?=E5=8D=A1=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configurations/SurgingServerOptions.cs | 2 ++ .../Surging.Core.CPlatform/Utilities/NetUtils.cs | 11 ++++++++++- .../Surging.Services.Server/surgingSettings.json | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Surging.Core/Surging.Core.CPlatform/Configurations/SurgingServerOptions.cs b/src/Surging.Core/Surging.Core.CPlatform/Configurations/SurgingServerOptions.cs index 1e3390d50..b26326445 100644 --- a/src/Surging.Core/Surging.Core.CPlatform/Configurations/SurgingServerOptions.cs +++ b/src/Surging.Core/Surging.Core.CPlatform/Configurations/SurgingServerOptions.cs @@ -55,5 +55,7 @@ public partial class SurgingServerOptions: ServiceCommand public string NotRelatedAssemblyFiles { get; set; } public string RelatedAssemblyFiles { get; set; } = ""; + + public string PreferredNetworks { get; set; } = ""; } } diff --git a/src/Surging.Core/Surging.Core.CPlatform/Utilities/NetUtils.cs b/src/Surging.Core/Surging.Core.CPlatform/Utilities/NetUtils.cs index 1195c7025..9f4b578c4 100644 --- a/src/Surging.Core/Surging.Core.CPlatform/Utilities/NetUtils.cs +++ b/src/Surging.Core/Surging.Core.CPlatform/Utilities/NetUtils.cs @@ -61,7 +61,7 @@ public static string GetAnyHostAddress() UnicastIPAddressInformationCollection ipCollection = ipxx.UnicastAddresses; foreach (UnicastIPAddressInformation ipadd in ipCollection) { - if (ipadd.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) + if (ipadd.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork&&IsPreferredAddress(ipadd.Address.ToString())) { result = ipadd.Address.ToString(); } @@ -71,6 +71,15 @@ public static string GetAnyHostAddress() return result; } + private static bool IsPreferredAddress(string hostAddress) + { + if (string.IsNullOrEmpty(AppConfig.ServerOptions.PreferredNetworks)) + { + return true; + } + return hostAddress.StartsWith(AppConfig.ServerOptions.PreferredNetworks); + } + public static string GetHostAddress(string hostAddress) { var result = hostAddress; diff --git a/src/Surging.Services/Surging.Services.Server/surgingSettings.json b/src/Surging.Services/Surging.Services.Server/surgingSettings.json index 58f6eba16..258003bc4 100644 --- a/src/Surging.Services/Surging.Services.Server/surgingSettings.json +++ b/src/Surging.Services/Surging.Services.Server/surgingSettings.json @@ -3,6 +3,7 @@ "Ip": "${Surging_Server_IP}|127.0.0.1", "WatchInterval": 30, "Port": "${Surging_Server_Port}|98", + "PreferredNetworks": "", "MappingIp": "${Mapping_ip}", "MappingPort": "${Mapping_Port}", "Token": "true",