如何在 WIPCAP 中知道哪些已安装的设备具有互联网连接?
我知道 winpcap 库使人能够获取有关已安装设备的高级信息...
考虑到计算机中找到的所有网络设备,我如何知道其中哪一个具有互联网连接?
谢谢:)
i have known that winpcap library enabled a person to obtain advanced information about installed devices...
given all the networking devices found in the computer, how will i know which one of this has an internet connection?!
thanks:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你通常不关心这个。通常您只需要求网络堆栈建立连接,而不用担心细节。
然而,每个“设备”都有自己的IP地址。您可以请求网络堆栈在建立连接时使用此 IP 地址。
现在,要确定哪些设备具有 Internet 连接,请迭代所有设备,获取它们的 IP 地址,并尝试创建从原始 IP 到 Internet 上的目标 IP 的连接。通常您已经知道这样的目标 IP,例如您公司的网络服务器。
You typically don't care about this. Normally you just ask the network stack to make a connection, and don't worry about details.
However, each "device" will have its own IP address. You can request the network stack to use this IP address when making a connection.
Now, to figure which devices have an intenet connection, iterate over all of them, obtain their IP address, and try to create a connection from that originating IP to a destination IP on the Internet. Typically you already know such a destination IP, e.g. your companies webserver.
GetAdaptersInfo() 将以某种形式提供所有已安装网络适配器的列表,然后您可以在 GetIfEntry() 中使用该列表。后一个功能将告诉您适配器的运行状态,因此您至少可以判断适配器是否已插入实时集线器/交换机/路由器。
如果您对 IP 连接特别感兴趣,您可以查看是否为该接口配置了默认网关。不要忘记,如果您尝试这样做,您可能必须支持 IPv6 和 IP4。
将 GetAdaptersInfo() 找到的网络适配器与 pcap_findalldevs() 找到的网络适配器关联起来作为读者的练习。我不记得细节了,但那是相当明显的。
GetAdaptersInfo() will give you a list of all network adapters installed in a form that you can then use in GetIfEntry(). This latter function will tell you the operational status of an adapter, so you can at least tell if the adapter is plugged into a live hub/switch/router.
If you are particularly interested in IP connectivity, you could look to see if a default gateway is configured for that interface. Don't forget you might have to support IPv6 as well as IP4 if you try this.
Correlating the network adapters found by GetAdaptersInfo() with those found by pcap_findalldevs() is left as an exercise for the reader. I don't remember the details but it was fairly obvious.