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",