Skip to content
Merged
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
22 changes: 20 additions & 2 deletions TouchSenderReceiver/Helpers/NetworkHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.NetworkInformation;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace TouchSenderReceiver.Helpers;
Expand All @@ -11,7 +12,7 @@ public class NetworkHelper
/// </summary>
/// <param name="networkInterfaceType"></param>
/// <returns></returns>
public static IList<string> GetAllLocalIPv4(NetworkInterfaceType networkInterfaceType = NetworkInterfaceType.Ethernet)
public static IList<string> GetAllLocalIPv4ByNIC(NetworkInterfaceType networkInterfaceType = NetworkInterfaceType.Ethernet)
{
List<string> ipAddrList = [];
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
Expand All @@ -29,4 +30,21 @@ public static IList<string> GetAllLocalIPv4(NetworkInterfaceType networkInterfac
}
return ipAddrList;
}

/// <summary>
/// Get all local IPv4 addresses of the current machine.
/// </summary>
public static IEnumerable<string> GetAllLocalIPv4()
{
string hostname = Dns.GetHostName();

IPAddress[] adrList = Dns.GetHostAddresses(hostname);
foreach (IPAddress address in adrList)
{
if (address.AddressFamily == AddressFamily.InterNetwork)
{
yield return address.ToString();
}
}
}
}
4 changes: 2 additions & 2 deletions TouchSenderTablet.GUI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading