How do you get the main IP address of the host machine?

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

Dns.GetHostAddresses(Dns.GetHostName())

This sometimes, depending on the configuration of the machine, can give you more than one IP address. So the question is, how to determine which is the primary IP address? Do you list network cards?

+3
source share
1 answer

There is no such thing as a “primary” IP address.

The routing table determines which external IP address is used depending on the destination IP address (as well as the extension, the network interface, which in itself can be virtual or physical).

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

+10

Source: https://habr.com/ru/post/1703538/


All Articles