2013-06-02 49 views
4

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

我发现这里的东西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); 

回答

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; 
} 
+0

我无法编译你已经发布了'+(double)getRouterLinkSpeed'的Xcode代码。 你能发表需要包含的标题吗? – user3355123

+0

#include #include suleymancalik

+1

谢谢suleyman !!你是我的英雄!! – user3355123

2

您可以使用NSURLConnection连接到您的测试服务器并下载一个类似1MB的预设文件。使用NSURLConnection代理-connection:didReceiveData:-connectionDidFinishLoading:来跟踪到目前为止的下载并从中计算下载速度。

+0

我不想测试网速,我只想测试调制解调器速度。 – suleymancalik

+1

好的...... ...... ......调制解调器连接到什么地方? – sangony

+0

@suleymancalik你的意思是你想测试你的设备和wifi路由器之间的连接速度吗? –