iOS获取链接速度(路由器速度测试) [英] iOS Get Link Speed (Router Speed Test)
问题描述
我想通过iOS应用测试连接的路由器(wifi调制解调器)的速度.
I want to test speed of connected router(wifi modem) from iOS app.
我在这里找到了一些东西以编程方式获取链接速度?,但是找不到sockios.h和ethtool.h
I've found something here Get link speed programmatically? but could not found sockios.h and ethtool.h
是否可以将此代码移植到Objective-C或还有另一种方法?
Is it possible to port this code to Objective-C or is there another way?
-
对不起,缺少信息和我的英语不好.
Sorry for the missing info and my poor english.
我想测试ios设备和连接的wifi调制解调器之间的链接速度(传输速率).
I want to test link speed (tx rate) between ios device and connected wifi modem.
在CWInterface类中有一个名为txRate的属性.我想在Cocoa Touch中获取这些数据.
There was a property named txRate in CWInterface class. I want to get that data in 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);
推荐答案
最后我找到了解决方案.
Finally I've found the solution.
#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;
}
这篇关于iOS获取链接速度(路由器速度测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!