你如何获得主机的主IP地址? [英] How do you get the host machine's primary IP address?
问题描述
调用下面给你回的所有IP地址的列表。
Calling the following gives you back a list of all the IP addresses.
Dns.GetHostAddresses(Dns.GetHostName())
这有时,取决于机器配置,可以给你回多个IP。所以,问题是,你如何确定哪些是主要的IP地址?你列举的NIC?
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?
推荐答案
有没有这样的事情作为一个主IP地址。
There's no such thing as a "primary" IP address.
路由表确定哪个外向IP地址被根据目的地的IP地址使用(通过扩展,网络接口,其本身可以是虚拟的或物理的)。
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).
如果你想看看路由表,使用的 IP帮助API 。
If you want to look at the routing table, use the IP Helper API.
这篇关于你如何获得主机的主IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!