The LINQ query to populate the networkIfaceIps var has a couple of problems:
the .Where logic should be || and not && for the NetworkInterfaceTypes. With && no interfaces are returned
the SortedSet constructor requires a template argument that supports IComparer - IPAddress does not so an exception is thrown when { ni, ip } pairs are actually returned. The simplest working change is
The LINQ query to populate the networkIfaceIps var has a couple of problems:
var networkIfaceIps = NetworkInterface.GetAllNetworkInterfaces() .Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet || ni.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet || ni.NetworkInterfaceType == NetworkInterfaceType.Loopback || ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.OperationalStatus == OperationalStatus.Up && !ni.IsReceiveOnly) .SelectMany(ni => ni.GetIPProperties().UnicastAddresses, (ni, ip) => new { ni, ip }) .Where(@t => @t.ip.Address.AddressFamily == AddressFamily.InterNetwork) .Select(@t => @t.ip.Address);
It is easy to extend the IPAddress type with a custom comparer (see stack hub and others) but probably not needed.
Andy