I am wondering if there is a reliable way to find the IPv4 address of the network adapter on my computer that is used to access the Internet (since this is the one to which I would like to bind my server). I used to get a list of local IP addresses:
IPAddress ip = System.Net.Dns.GetHostByName(Environment.MachineName).AddressList[0];
And it worked fine, but today it failed, because the IP address I was looking for was not the first in this list of addresses, but the third (since I had 2 virtual machines, and both of them created a virtual adapter).
Any advice would be highly appreciated.
source share