Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ public partial class SurgingServerOptions: ServiceCommand
public string NotRelatedAssemblyFiles { get; set; }

public string RelatedAssemblyFiles { get; set; } = "";

public string PreferredNetworks { get; set; } = "";
}
}
11 changes: 10 additions & 1 deletion src/Surging.Core/Surging.Core.CPlatform/Utilities/NetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down