Windows中如何确定哪个是活动适配器?
我有多个适配器,就像 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您所说的“活动一”是什么意思,所以我假设您的意思是“哪个网络适配器是访问互联网的默认网络适配器”?
调用 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 thedwForwardDest
set to 0 (which can happen if you have more than one adpater), then use thedwForwardMetric1
member as the tie-breaker (lowest value wins).Once you find the default route row from
GetIpForwardTable
, you can use thedwForwardIfIndex
member to identify which adapter in a call to GetIfTable is the default.