From 051932f544cb0aaa3051e03e526be5a80c8d2ccf Mon Sep 17 00:00:00 2001 From: Derek S <44935661+Derek-R-S@users.noreply.github.com> Date: Tue, 6 Apr 2021 21:00:23 -0500 Subject: [PATCH] Make LLB only bind to local ipv4 addresses --- .../LRM_LoadBalancer/Endpoint.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs index 32c3dae..194e16e 100644 --- a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs +++ b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs @@ -184,8 +184,8 @@ namespace LightReflectiveMirror.LoadBalancing services.Configure(options => options.MinLevel = LogLevel.None); }, (server) => { - server.Prefixes.Add($"http://{GetLocalIp()}:{port}/"); - server.Prefixes.Add($"http://*:{port}/"); + foreach(string ip in GetLocalIps()) + server.Prefixes.Add($"http://{ip}:{port}/"); }).Build(); server.Router.Options.SendExceptionMessages = false; @@ -199,19 +199,20 @@ namespace LightReflectiveMirror.LoadBalancing } } - private static string GetLocalIp() + private static List GetLocalIps() { var host = Dns.GetHostEntry(Dns.GetHostName()); + List bindableIPv4Addresses = new(); foreach (var ip in host.AddressList) { - if (ip.AddressFamily == AddressFamily.InterNetwork && ip.ToString() != "127.0.0.1") + if (ip.AddressFamily == AddressFamily.InterNetwork) { - return ip.ToString(); + bindableIPv4Addresses.Add(ip.ToString()); } } - return null; + return bindableIPv4Addresses; } #endregion