iOS获取链接速度(路由器速度测试)

时间:2013-06-02 01:36:46

标签: ios cocoa-touch wifi

我想从iOS应用程序测试连接路由器(wifi调制解调器)的速度。

我在Get link speed programmatically?找到了一些东西,但找不到sockios.h和ethtool.h

是否可以将此代码移植到Objective-C或是否有其他方法?

-

抱歉缺少信息和我的英语不好。

我想测试ios设备和连接的wifi调制解调器之间的链接速度(tx速率)。

CWInterface类中有一个名为txRate的属性。我想在Cocoa Touch中获取这些数据。

/*!
* @property
* @abstract Current transmit rate (Mbps) of the CoreWLAN interface. 
* @discussion Dynamically queries the interface for the current transmit rate.
*/
@property(readonly) NSNumber *txRate NS_DEPRECATED_MAC(10_6, 10_7);

3 个答案:

答案 0 :(得分:4)

最后我找到了解决方案。

#include <ifaddrs.h>
#include <net/if.h>

+ (double)getRouterLinkSpeed
{
    BOOL   success;
    struct ifaddrs *addrs;
    const struct ifaddrs *cursor;
    const struct if_data *networkStatisc;

    double linkSpeed = 0;

    NSString *name = [[NSString alloc] init];

    success = getifaddrs(&addrs) == 0;
    if (success)
    {
        cursor = addrs;
        while (cursor != NULL)
        {
            name=[NSString stringWithFormat:@"%s",cursor->ifa_name];

            if (cursor->ifa_addr->sa_family == AF_LINK)
            {
                if ([name hasPrefix:@"en"])
                {
                    networkStatisc = (const struct if_data *) cursor->ifa_data;
                    linkSpeed = networkStatisc->ifi_baudrate;
                }
            }
            cursor = cursor->ifa_next;
        }
        freeifaddrs(addrs);
    }

    return linkSpeed;
}

答案 1 :(得分:2)

您可以使用NSURLConnection连接到测试服务器并下载1 MB之类的预设文件。使用NSURLConnection委托-connection:didReceiveData:-connectionDidFinishLoading:跟踪“到目前为止”的下载并计算下载速度。

答案 2 :(得分:0)

目前尚无官方(或Apple批准)在iOS上获取LinkSpeed的方法。过去有漏洞,但是很遗憾,这些漏洞已经关闭。

您可以用来估计LinkSpeed的最相似的度量标准是通过在本地网络上发送UDP数据包并测量其发送速率来测量wifi速度。这称为IP数据包发送比特率,在ITU标准https://www.itu.int/rec/T-REC-Y.1540/en

中定义

该wifi速度测量的iOS实现在我们的iOS SDK中,您可以在这里找到:

https://github.com/speedchecker/speedchecker-sdk-ios

此实现是最接近的估计路由器wifi速度的方法,而无需实际在路由器本身上放置任何有效载荷文件。