捕获 VPN 使用统计数据
我们正在使用 .NET 2.0 中的 NetworkInterface.GetIPv4Statistics() 来监视网络接口的使用统计信息。 这不会报告 VPN 流量通过隧道传输的连接的正确统计信息。 相反,对于 Cisco VPN 客户端,其使用仅归因于看起来像以太网连接的新网络接口。
Windows 本身(至少是 Vista)将 VPN 统计数据正确添加到实际物理接口,因此查看原始连接的“状态”对话框会显示正确的字节计数。 但是,.NET 中的调用结果不会将流量合并在一起。
有没有办法将 VPN 连接关联回其通过隧道传输的网络连接? 如果做不到这一点,有谁知道状态对话框正在使用哪个 API 来检索正确的统计信息?
目前,我们必须手动检测看起来像是 VPN 的连接,并将其使用情况添加到任何其他活动连接中,这似乎不是一个可靠的解决方案。
We're monitoring usage statistics of a network interface using NetworkInterface.GetIPv4Statistics() in .NET 2.0. This isn't reporting correct statistics for connections over which VPN traffic is being tunneled. Instead - in the case of the Cisco VPN client - the usage is just attributed to a new network interface that just looks like an Ethernet connection.
Windows itself (Vista, at least) adds the VPN statistics to the actual physical interface correctly, so viewing the 'Status' dialog for the original connection shows the correct byte counts. However, the results of the call in .NET do not merge the traffic together.
Is there a way to associate the VPN connection back to the network connection over which it's being tunneled? Failing that, does anyone know which API is being used by the status dialog to retrieve correct statistics?
At the moment we're having to manually detect connections that look like they're VPNs and add their usage to whatever other connection is active, and this doesn't seem like a robust solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个用 Delphi 编写的程序(带有完整的源代码和解释)将帮助您收集网络信息,包括 VPN 数据。 这是使用开源 Indy 组件,该组件也可供使用使用 C#。
我建议浏览源代码,您将找到它所进行的确切 Windows API 调用。 它严重依赖于 IP Helper API (IPHlpApi)。
如果您正在寻找仅 C# 的示例,我建议您在 google 上搜索“C# 和 IpHlpApi”。
问候
替代文本 http://z.about.com /d/delphi/1/0/k/2/112903_2.gif
Here's a program written in Delphi (with full source and explanation) that will help you to collect network information, including VPN data. This is using the open-source Indy components, which is also available for use with C#.
I'd suggest browsing through the source, and you'll find the exact Windows API calls it makes. It relies HEAVILY on the IP Helper API (IPHlpApi).
If you are looking for C# only examples, I'd suggest doing some google-ing for "C# and IpHlpApi".
Regards
alt text http://z.about.com/d/delphi/1/0/k/2/112903_2.gif
我必须在上班时检查一下我的配置。
Cisco VPN 所做的一件事是(如果配置)禁用分割隧道。 这意味着您将无法通过连接到 VPN 的连接访问本地子网。
我看到这一点的方式是,当我的以太网连接配置了 IP 地址,但没有默认网关时。
假设您识别 VPN 连接,则该无网关连接将是您的其他连接。
另外,您是否研究过任何 WMI 类。 Cisco VPN 或许可以与 WMI 类交互。
I'll have to check when I get to work to see what my config looks like.
One thing that Cisco VPN does is, if configured, disabling split tunneling. What that means is that you are prevented from accessing your local subnet on the connection that is connected to VPN.
The way I can see this, is when my ethernet connection is configured with an IP Address, but doesn't have a Default Gateway.
Supposing that you identify the VPN connection, that gateway-less connection would be your other connection.
Also, have you looked into any WMI classes. Cisco VPN may interact with a WMI class perhaps.
正如 Rob 所言,答案就在 WMI 中。
Win32_PerfFormattedData_RemoteAccess_RasPort
似乎与 Windows 本身使用的完全相同 - 无论 VPN 是否启动,数字都是相同的,逐个字节。我测试过:
As Rob suggests, the answer lies within WMI.
Win32_PerfFormattedData_RemoteAccess_RasPort
seems to be exactly what Windows uses itself - the numbers are the same, byte for byte, whether the VPN is up or not.I tested with: