苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 9182|回复: 6
打印 上一主题 下一主题

[Asp.Net] asp.net 获取网速

[复制链接]
跳转到指定楼层
楼主
发表于 2013-3-25 17:00:47 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
asp.net  怎么获取网速?求解!


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
沙发
发表于 2013-3-25 17:10:59 | 只看该作者
你要用在什么地方,如果是上传的可以自行根据上传的数据进行计算
板凳
 楼主| 发表于 2013-3-25 17:13:52 | 只看该作者
站长苏飞 发表于 2013-3-25 17:10
你要用在什么地方,如果是上传的可以自行根据上传的数据进行计算

根据网速跳转页面,js能判断也可以。
地板
 楼主| 发表于 2013-3-25 17:22:23 | 只看该作者
.net 发表于 2013-3-25 17:13
根据网速跳转页面,js能判断也可以。

就在asp.net中怎么判断
5
发表于 2013-3-25 17:32:45 | 只看该作者
.net 发表于 2013-3-25 17:22
就在asp.net中怎么判断

http://www.codeproject.com/Articles/6259/Monitoring-network-speed  参考下这个吧
源码下载 Network_Monitor_Demo.zip (13.98 KB, 下载次数: 336)
虽说是Winform的不过可以恩成Asp.net的
主要看思路

IntroductionThe .NET Class Library provides a set of performance counters that you can use to track the performance both of the system and of an application. This program makes use of counters in the Networking category to obtain information about data sent and received over the network, and calculates network speed.
Using the codeThis library includes only two classes, NetworkMonitor and NetworkAdapter. The former one provides general methods to enumerate network adapters installed on a computer, start or stop watching specified adapter, and a timer to read performance counter samples every second, and the latter represents a specific network adapter, providing properties presenting current speed.
The following code is a simple example of using these two classes:
    [code=csharp]NetworkMonitor monitor    =    new NetworkMonitor();
    NetworkAdapter[] adapters    =    monitor.Adapters;

    // If the length of adapters is zero, then no instance
    // exists in the networking category of performance console.
    if (adapters.Length == 0)
    {
        Console.WriteLine("No network adapters found on this computer.");
        return;
    }

    // Start a timer to obtain new performance counter sample every second.
    monitor.StartMonitoring();

    for( int i = 0; i < 10; i ++)
    {
        foreach(NetworkAdapter adapter in adapters)
        {
            // The Name property denotes the name of this adapter.
            Console.WriteLine(adapter.Name);
            // The DownloadSpeedKbps and UploadSpeedKbps are
            // double values. You can also use properties DownloadSpeed
            // and UploadSpeed, which are long values but
            // are measured in bytes per second.
            Console.WriteLine(String.Format("dl: {0:n} " +
               "kbps\t\tul: {1:n} kbps? adapter.DownloadSpeedKbps,
               adapter.UploadSpeedKbps));
        }
        System.Threading.Thread.Sleep(1000); // Sleeps for one second.
    }

    // Stop the timer. Properties of adapter become invalid.
    monitor.StopMonitoring ();[/code]Points of InterestTo enumerate the network adapters on a computer, I only utilize the existing interface names in the networking category of performance console. Here is the EnumerateNetworkAdapters() method.
   [code=csharp] /// <summary>
    /// Enumerates network adapters installed on the computer.
    /// </summary>
    private void EnumerateNetworkAdapters()
    {
        PerformanceCounterCategory category    =
          new PerformanceCounterCategory("Network Interface");

        foreach (string name in category.GetInstanceNames())
        {
            // This one exists on every computer.
            if (name == "MS TCP Loopback interface")
                continue;
            // Create an instance of NetworkAdapter class,
            // and create performance counters for it.
            NetworkAdapter adapter = new NetworkAdapter(name);
            adapter.dlCounter = new PerformanceCounter("Network Interface",
                                                "Bytes Received/sec", name);
            adapter.ulCounter = new PerformanceCounter("Network Interface",
                                                    "Bytes Sent/sec", name);
            this.adapters.Add(adapter);    // Add it to ArrayList adapter
        }
    }[/code]A tricky problem with this approach is that an instance called “MS TCP Loopback interface” exists on every computer, of which both the download speed and the upload speed are always zero. So I explicitly check and exclude it in the program, which is certainly not a good manner but workable.
Before all of this, I tried to accomplish this by making a WMI query, which looked more decent, and my first version went like this:
   [code=csharp] ///
    /// Enumerates network adapters installed on the computer.
    ///
    private void EnumerateNetworkAdapters()
    {
        // Information about network adapters can be found
        // by querying the WMI class Win32_NetworkAdapter,
        // NetConnectionStatus = 2 filters the ones that are not connected.
        // WMI related classes are located in assembly System.Management.dll
        ManagementObjectSearcher searcher = new
            ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter" +
                                            " WHERE NetConnectionStatus=2");

        ManagementObjectCollection adapterObjects = searcher.Get();

        foreach (ManagementObject adapterObject in adapterObjects)
        {
            string name    =    adapterObject["Name"];

            // Create an instance of NetworkAdapter class,
            // and create performance counters for it.
            NetworkAdapter adapter = new NetworkAdapter(name);
            adapter.dlCounter = new PerformanceCounter("Network Interface",
                                                "Bytes Received/sec", name);
            adapter.ulCounter = new PerformanceCounter("Network Interface",
                                                    "Bytes Sent/sec", name);
            this.adapters.Add(adapter); // Add it to ArrayList adapter
        }
    }[/code]The only problem is that the name of an adapter obtained this way will possibly differ from the instance name needed to create a performance counter. On my machine, this name is "Intel(R) PRO/100 VE Network Connection" querying WMI, and "Intel[R] Pro_100 VE Network Connection" in the performance console. I did not find a better solution and finally gave up WMI.
6
发表于 2013-5-28 16:03:54 | 只看该作者
站长苏飞 发表于 2013-3-25 17:32
http://www.codeproject.com/Articles/6259/Monitoring-network-speed  参考下这个吧
源码下载
虽说是W ...

谢谢分享 不过这个貌似跟360显示的不一样?
7
发表于 2013-7-5 14:48:19 | 只看该作者
这个功能不错,实用啊
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2025-2-23 07:15

© 2014-2021

快速回复 返回顶部 返回列表