2013-06-02 47 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路由器之間的連接速度嗎? –