diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index 0a41755c..279b63c4 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -26,9 +26,10 @@ using Fika.Core.UI; using Fika.Core.UI.Models; using Fika.Core.UI.Patches; +using System; using System.Collections.Generic; using System.Linq; -using System.Net; +using System.Net.NetworkInformation; using System.Net.Sockets; using System.Reflection; using System.Text; @@ -383,19 +384,39 @@ private void SetupConfig() private string[] GetLocalAddresses() { - IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); List ips = []; ips.Add("Disabled"); - foreach (IPAddress ip in host.AddressList) - { - if (ip.AddressFamily == AddressFamily.InterNetwork) + ips.Add("0.0.0.0"); + + try + { + foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces()) { - ips.Add(ip.ToString()); + foreach (UnicastIPAddressInformation ip in networkInterface.GetIPProperties().UnicastAddresses) + { + if (!ip.IsDnsEligible) + { + continue; + } + + if (ip.Address.AddressFamily == AddressFamily.InterNetwork) + { + string stringIp = ip.Address.ToString(); + if (stringIp != "127.0.0.1") + { + ips.Add(stringIp); + } + } + } } - } - LocalIPs = ips.Skip(1).ToArray(); - return [.. ips]; + LocalIPs = ips.Skip(1).ToArray(); + return [.. ips]; + } + catch (Exception) + { + return [.. ips]; + } } private void DisableSPTPatches()