Capturing VPN usage statistics

We track network interface usage statistics using NetworkInterface.GetIPv4Statistics () in .NET 2.0. This does not indicate the correct statistics for the connections over which VPN traffic is tunneled. Instead - in the case of the Cisco VPN client - the use is simply explained by the new network interface, which just looks like an Ethernet connection.

Windows itself (at least Vista) automatically adds VPN statistics to the real physical interface, so looking at the Status dialog box for the original connection shows the correct number of bytes. However, the call results in .NET do not combine traffic together.

Is there a way to associate a VPN connection with the network connection through which it is tunneling? Otherwise, does anyone know which API is used in the status dialog to get the right statistics?

At the moment, we have to manually detect connections that look like their VPNs and add their use to any other connection, and this does not seem like a reliable solution.

+3
source share
3 answers

According to Rob, the answer lies in WMI. Win32_PerfFormattedData_RemoteAccess_RasPortIt seems exactly what Windows uses on its own - the numbers are the same, bytes for a byte, regardless of whether the VPN is up or not.

I tested with:

static class Program
{
    static void Main()
    {
        var query = new WqlEventQuery("__InstanceModificationEvent", TimeSpan.FromSeconds(1),
                                      "TargetInstance ISA 'Win32_PerfFormattedData_RemoteAccess_RasPort' AND TargetInstance.BytesReceived > 0");

        var watcher = new ManagementEventWatcher(query);
        watcher.EventArrived += EventArrived;
        watcher.Start();

        Console.ReadLine();
    }

    static void EventArrived(object sender, EventArrivedEventArgs e)
    {
        var mo = e.NewEvent["TargetInstance"] as ManagementBaseObject;
        Console.WriteLine("{0:#,0}: {1:#,0} bytes sent, {2:#,0} bytes received", mo["Name"], mo["BytesTransmitted"], mo["BytesReceived"]);
    }
}
0
source

, Delphi ( ), , VPN. Indy , #.

, Windows API, . HEAVILY API- IP Helper (IPHlpApi).

#, google-ing "# IpHlpApi".

alt text http://z.about.com/d/delphi/1/0/k/2/112903_2.gif

+2

, , , .

, Cisco VPN , , -. , , VPN.

, Ethernet IP-, .

, VPN-, .

, WMI. Cisco VPN WMI, .

+1

Source: https://habr.com/ru/post/1703498/


All Articles