I am trying to find a magic answer to the "primary IP address" of the system. My research has determined that the answer to "best" means this:
- Take a look at [system.Net.NetworkInformation.NetworkInterface] :: GetAllNetworkInterfaces () for interfaces with default gateways assigned. If you only find it, then you are done.
- If there are several, you need to look at the routing table for the one that has the lowest metric (look at the network entries 0.0.0.0).
- In the case of binding to the metric, the adapter with the lowest binding order wins.
My question is: how do you determine the binding order using .NET? I saw a solution that looks at the registry and this is good, but I was hoping for a more beautiful interface.
Reward points for PowerShell samples as my language of choice. :)
source
share