如何确定主网络适配器? [英] How to determine primary network adapter?

查看:90
本文介绍了如何确定主网络适配器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想在我的系统中用C ++代码获取(识别,确定)适配器网卡(主要)。



我尝试了什么:



我使用getNetworkParam,GetInterfaceInfo等,但这个功能都无法帮助我确定主网卡。

hello,
I want get(recognize, determine) adapter network card (primary) in my system with C++ code.

What I have tried:

I use getNetworkParam, GetInterfaceInfo, and etc, but none of this function, can't help me for determine primary network card.

推荐答案

首先,你必须定义什么使网络适配器成为主网卡,因为没有固定的定义。



一个常见的定义是那些适配器是用于连接到互联网的主要适配器。然后,它有一个(或多个)网关地址(路由)。您可以获取网络适配器列表并致电 GetAdaptersInfo功能(Windows) [ ^ ]每个人检查 GatewayList



但是请注意,单个适配器可能有多个网关,并且多个适配器可以配置网关。在后一种情况下,您将有多个主适配器用于此类定义。



如果您的系统是互联网域(本地或全球)的一部分,另一个定义是绑定到此域的adpater是主域。如果是这样,请使用 GetNetworkParams功能(Windows) [ ^ ]获取 HostName 。如果这是一个完全限定的主机名,请解析它以获取IP地址(DNS查询),然后指示这种定义的主适配器。
At first you have to define what makes a network adapter the primary one because there is no fixed definition.

A common definition is that those adapter is the primary one that is used to connect to the internet. Then this has one (or more) gateway addresses (routes). You can get a list of your network adapters and call GetAdaptersInfo function (Windows)[^] for each of them checking the GatewayList.

But note that there might be multiple gateways for a single adapter and that multiple adapters can have gateways configured. In the latter case you would have multiple "primary" adapters for this kind of definition.

If your system is part of a internet domain (local or world wide), another definition is that the adpater bound to this domain is the primary one. If so, use the GetNetworkParams function (Windows)[^] to get the HostName. If that is a fully qualified hostname, resolve it to get the IP address (DNS query) which is then indicating the "primary" adapter for this kind of definition.


这篇关于如何确定主网络适配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆