Windows中如何确定哪个是活动适配器?

发布于 2024-12-27 09:43:24 字数 119 浏览 2 评论 0原文

我有多个适配器,就像 Windows 中的默认适配器、wifi 网络、带 USB 的 3G 卡等。 如何确定哪一个是活动?我尝试使用 GetAdaptersInfo/GetIfEntry 但没有答案。有人可以给我一些建议吗?

I have multiple adapters just like default one, wifi-net, 3G card with usb etc in Windows.
How to determine which is the activity one? I tried to use GetAdaptersInfo/GetIfEntry but there is no answer. Could someone give me some suggest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2025-01-03 09:43:24

我不确定您所说的“活动一”是什么意思,所以我假设您的意思是“哪个网络适配器是访问互联网的默认网络适配器”?

调用 GetIpForwardTable 。枚举 MIB_IPFORWARDROW 表内的实例。 dwForwardDest 成员设置为零的行是默认路由。如果 dwForwardDest 设置为 0 的行以上(如果您有多个适配器,则可能会发生这种情况),则使用 dwForwardMetric1 成员作为 tie-断路器(最低值获胜)。

GetIpForwardTable 找到默认路由行后,您可以使用 dwForwardIfIndex 成员来识别对 GetIfTable是默认值。

I'm not sure what you mean by "activity one", so I'll assume you mean "which network adapter is the default for reaching the internet"?

Call GetIpForwardTable. Enumerate the MIB_IPFORWARDROW instances within the table. The rows with the dwForwardDest member set to zero are the default routes. In the event of more than one row with the dwForwardDest set to 0 (which can happen if you have more than one adpater), then use the dwForwardMetric1 member as the tie-breaker (lowest value wins).

Once you find the default route row from GetIpForwardTable, you can use the dwForwardIfIndex member to identify which adapter in a call to GetIfTable is the default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文