Let’s say my computer A is connected to multiple networks. On one of these networks is another host, B.
Is it possible, through C# from host A, to determine how host B would reach host A? The solution must handle both IPv4 and IPv6. It doesn’t need to handle NAT.
One could say I want to figure out which one of host A’s network interfaces is connected to host B.
It is never possible to tell how another host will reach you because it is up to that host’s route table.
However, usually routes are symmetric which means a remote host will reach you the same way you will reach that remote host. You can examine the route table. On Windows that command would be “route -n”. This is probably exposed via some API too.
If host A and B are already connected, that connection will show up in netstat.
If you control the code that has the connected socket then you just need to get the peer. Sorry I don’t have the C# code to do that.