ipnetwork
ipnetwork copied to clipboard
Definition whether remote IPv6-address is in the same network
Is there any way to define whether remote IPv6-address is in the same network? I have connected NetworkInterface object, but I didn't find any way to define this. I have tried to get first link local IPv6 of interface:
IPAddress ipv6LinkLocalAddress = networkInterface.GetIPProperties().UnicastAddresses.FirstOrDefault( c => c.Address.IsIPv6LinkLocal )?.Address;
IPNetwork ipNetwork = ipv6LinkLocalAddress != null ? IPNetwork.Parse( ipv6LinkLocalAddress, SubnetMask.ClassC ) : null;
isSameNetwork = ( ipNetwork != null ) && ipNetwork.Contains( remoteAddress );
But this returns true
, when networks is different