diff --git a/TouchSenderReceiver/Helpers/NetworkHelper.cs b/TouchSenderReceiver/Helpers/NetworkHelper.cs index 62acc49..ba19f9d 100644 --- a/TouchSenderReceiver/Helpers/NetworkHelper.cs +++ b/TouchSenderReceiver/Helpers/NetworkHelper.cs @@ -1,4 +1,5 @@ -using System.Net.NetworkInformation; +using System.Net; +using System.Net.NetworkInformation; using System.Net.Sockets; namespace TouchSenderReceiver.Helpers; @@ -11,7 +12,7 @@ public class NetworkHelper /// /// /// - public static IList GetAllLocalIPv4(NetworkInterfaceType networkInterfaceType = NetworkInterfaceType.Ethernet) + public static IList GetAllLocalIPv4ByNIC(NetworkInterfaceType networkInterfaceType = NetworkInterfaceType.Ethernet) { List ipAddrList = []; foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces()) @@ -29,4 +30,21 @@ public static IList GetAllLocalIPv4(NetworkInterfaceType networkInterfac } return ipAddrList; } + + /// + /// Get all local IPv4 addresses of the current machine. + /// + public static IEnumerable GetAllLocalIPv4() + { + string hostname = Dns.GetHostName(); + + IPAddress[] adrList = Dns.GetHostAddresses(hostname); + foreach (IPAddress address in adrList) + { + if (address.AddressFamily == AddressFamily.InterNetwork) + { + yield return address.ToString(); + } + } + } } diff --git a/TouchSenderTablet.GUI/ViewModels/MainViewModel.cs b/TouchSenderTablet.GUI/ViewModels/MainViewModel.cs index 7677cf3..7809c27 100644 --- a/TouchSenderTablet.GUI/ViewModels/MainViewModel.cs +++ b/TouchSenderTablet.GUI/ViewModels/MainViewModel.cs @@ -112,8 +112,8 @@ public MainViewModel(ITouchReceiverSettingsService touchReceiverSettingsService, _serviceOptions = _touchReceiverSettingsService.ServiceOptions; _screenOptions = _touchReceiverSettingsService.ScreenOptions; - var candidateIpAddresses = NetworkHelper.GetAllLocalIPv4(); - IpAddresses = candidateIpAddresses.Count > 0 ? string.Join(" / ", NetworkHelper.GetAllLocalIPv4()) : "Unknown".GetLocalized(); + var candidateIpAddresses = NetworkHelper.GetAllLocalIPv4().ToList(); + IpAddresses = candidateIpAddresses.Count > 0 ? string.Join(" / ", candidateIpAddresses) : "Unknown".GetLocalized(); } private void SetInitialCanvas()