tags:

views:

639

answers:

1

Calling the following gives you back a list of all the IP addresses.

Dns.GetHostAddresses(Dns.GetHostName())

This sometimes, depending on machine configuration, could give you back more than one IP. So the question is, how do you determine which is the primary IP address? Do you enumerate the NICs?

+9  A: 

There's no such thing as a "primary" IP address.

The routing table determines which outward-facing IP address is used depending on the destination IP address (and by extension, the network interface, which itself can be virtual or physical).

If you want to look at the routing table, use the IP Helper API.

Jason Cohen
+1. Use the first one in the list. Or the last. It doesn't matter. If they're in DNS, then all of them should work. If they don't work, they shouldn't be in DNS. Quad erat something-or-other :-)
paxdiablo
There is an order that multiple NICs are used in (in XP, Network Connections > Advanced > Advanced Settings) but this may be more in depth than the question is asking.
routeNpingme