在C#中,我使用DotRas开发了一个Vpn客户端,但我想显示VPN连接的服务器的速度以及下载和发送的字节数。
我尝试了以下代码,但不确定:
代码:
public static void ShowInterfaceSpeedAndQueue()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
IPv4InterfaceStatistics stats = adapter.GetIPv4Statistics();
Console.WriteLine(adapter.Description);
Console.WriteLine(" Speed .................................: {0}",
((adapter.Speed / 1024) / 1024) +" " + "MB");
Console.WriteLine(" Output queue length....................: {0}",
stats.OutputQueueLength);
Console.WriteLine(" Bytes Recieved ....................: {0}",
((stats.BytesReceived / 1024) / 1024) + " " + "MB");
Console.WriteLine(" Bytes Sent ....................: {0}",
((stats.BytesSent / 1024) / 1024) + " " + "MB");
}
}