ipnetwork icon indicating copy to clipboard operation
ipnetwork copied to clipboard

Definition whether remote IPv6-address is in the same network

Open bob-byte opened this issue 2 years ago • 0 comments

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

bob-byte avatar Jun 13 '22 15:06 bob-byte