我想从 iOS 应用程序测试连接的路由器(wifi 调制解调器)的速度。
我在这里找到了一些东西以编程方式获取链接速度? https://stackoverflow.com/questions/2872058/get-link-speed-programmatically但找不到 sockios.h 和 ethtool.h
是否可以将此代码移植到 Objective-C 或者还有其他方法?
--
抱歉缺少信息和我糟糕的英语。
我想测试 ios 设备和连接的 wifi 调制解调器之间的链接速度(发送速率)。
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);
最后我找到了解决方案。
#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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)