如何枚举所有可用的网络接口?
如何枚举计算机上当前可用的所有网络接口(包括虚拟、非连接、环回等)?
我需要知道他们的 IP4/6、掩码、网关、DNS、WINS 等
语言: C++、WinAPI
系统: Windows 2000 及更高版本(包括 Win7)
How to enumerate all network interfaces currently available on the computer (including virtual, non-connected, loopback etc)?
I need to know their IP4/6, Mask, Gateway, DNS, WINS etc
Language: C++, WinAPI
System: Windows 2000 and higher (including Win7)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您想要一些不同功能的组合。
要获取适配器列表及其 IPv4 地址/掩码、关联的 WINS 服务器和 DNS 服务器,您可以使用
GetAdaptersInfo
。要获取 IPv6 地址,您可以使用GetAdaptersAddresses
。取决于您的“等”中包含的内容。您可能还需要
GetIfTable
和GetIfEntry
。GetIfTable
获取网络适配器列表。GetIfEntry
获取有关每个条目的信息。这些检索诸如通过特定接口传输/检索的数据量之类的内容。还有一个GetIfTable2
/GetIfEntry2
仅适用于 Vista 及更高版本,可获取更多信息。如果没记错的话,
GetIfTable
/GetIfEntry
会列出机器中的所有接口。GetAdaptersInfo
仅适用于“真正的”适配器。It sounds like you want a combination of a few different functions.
To get a list of adapters with their IPv4 addresses/masks, associated WINS servers and DNS servers, you can use
GetAdaptersInfo
. To get IPv6 addresses, you can useGetAdaptersAddresses
.Depending on what is included in your "etc." you might also want
GetIfTable
andGetIfEntry
.GetIfTable
gets a list of network adapters.GetIfEntry
gets you information about each. These retrieve things like the amount of data that's been transmitted/retrieved over a particular interface. There's also aGetIfTable2
/GetIfEntry2
that are only for Vista and newer that get more information.If memory serves,
GetIfTable
/GetIfEntry
list all the interfaces in the machine.GetAdaptersInfo
only works with the "real" adapters.相反,您可以使用
getaddrinfo ("..localmachine")
枚举 Windows 2003+ 上的接口。http://msdn.microsoft.com/en- us/library/ms738520(v=vs.85).aspx
Windows 7 Service Pack 1 (SP1) 和 Windows Server 2008 R2 Service Pack 1 (SP1) 添加了对隐藏界面的支持。
http://support.microsoft.com/kb/2386184
Perversely you can use
getaddrinfo ("..localmachine")
to enumerate interfaces on Windows 2003+.http://msdn.microsoft.com/en-us/library/ms738520(v=vs.85).aspx
Windows 7 with Service Pack 1 (SP1) and Windows Server 2008 R2 with Service Pack 1 (SP1) add support to hide interfaces.
http://support.microsoft.com/kb/2386184