使用私有 API 在 iOS 7 上扫描网络 (SSID)

Scan networks (SSID#39;s) on iOS 7 by using private API(使用私有 API 在 iOS 7 上扫描网络 (SSID))

本文介绍了使用私有 API 在 iOS 7 上扫描网络 (SSID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过在 iOS 7 越狱设备上使用私有 API 来获取周围网络的 SSID 列表?

Is it possible to get list of SSID's of networks around by using private API on iOS 7 Jailbroken device?

我知道在 iOS 上管理 WiFi 功能的 MobileWiFi.framework.(它取代了过时的 Apple80211 框架.)

I know about MobileWiFi.framework that manages WiFi functionality on iOS. (It replaces the obsolete Apple80211 framework.)

这是 4 岁的答案如何使用它:访问&使用 MobileWiFi.framework

Here is 4 years old answer how to use it: Accessing & Using the MobileWiFi.framework

我尝试在 iOS 7 上使用这些方法,但没有成功.

I tried to use these methods on iOS 7, but have no luck.

在此解决方案作者的评论之一中,我收到了这个答案:

In one of the comments of author of this solution I receive this answer:

scanNetworks 失败,因为该代码现已使用 4 年.正如我在回答中所描述的,您必须使用新框架来获得等效功能(至少从 iOS 5 开始您就必须这样做).如果您尝试使用 iOS 7 执行此操作,我建议您发布一个新问题.

附言

这不是 获取 iOS 范围内的 SSID 的重复7 .我问一下这些功能的越狱方法.

UPD:

上面的链接和 creker 的答案中都有工作代码.但它需要通过沙盒限制.所以,正确的问题是:有没有办法用常规的 iOS 应用程序做到这一点?

There is working code in the link above and in the creker's answer too. But it's needed to pass the sandbox restrictions. So, the right question is: Is there a way to do that with regular iOS app?

推荐答案

这是我在iOS5-7上使用的

Here is what I use on iOS5-7

void* library = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);

int (*apple80211Open)(void*) = (int(*)(void*))dlsym(library, "Apple80211Open");
int (*apple80211Bind)(void*, NSString*) = (int(*)(void*, NSString*))dlsym(library, "Apple80211BindToInterface");
int (*apple80211Close)(void*) = (int(*)(void*))dlsym(library, "Apple80211Close");
int (*apple80211Scan)(void*, NSArray**, void*) = (int(*)(void*, NSArray**, void*))dlsym(library, "Apple80211Scan");

void *airport = NULL;
apple80211Open(&airport);
apple80211Bind(airport, @"en0");

NSArray* networks = nil;
apple80211Scan(airport, &networks, [NSDictionary dictionary]);

//"networks" is an array of NSDictionary objects for all the visible Wi-Fi networks

apple80211Close(airport);
dlclose(library); 

IPConfiguration 不是胖二进制文件.它仅包含一种与设备匹配的架构.因此,如果您计划支持 arm64 设备,您还必须为 arm64 编译代码 - 32 位应用程序无法加载 64 位 dylib.armv7 和 arm64 足以满足所有现代设备的需求.

IPConfiguration is not a fat binary. It contains only one architecture matching the device. Thus if you're planning on supporting arm64 devices you have to compile your code for arm64 also - 32-bit applications can't load 64-bit dylibs. armv7 and arm64 are enough for all modern devices.

更新

不幸的是,即使在越狱设备上,此代码也无法在常规 iOS 应用中运行.越狱不会关闭沙箱,这就是代码不起作用的原因.要使此代码正常工作,您需要将应用程序放在未应用沙盒限制的 /var/mobile/Applications 目录之外.它可以是 /Applications 目录中的守护进程、tweak 或 GUI 应用程序.该目录内的应用程序默认没有任何限制,可以访问任何私有 API.

Unfortunatelly this code doesn't work in regular iOS apps even on jailbroken device. Jailbreak doesn't turn off the sandbox which is the reason the code doesn't work. For this code to work you need to place your application outside /var/mobile/Applications directory where sandbox restrictions aren't applied. It could be a daemon, a tweak or a GUI application inside /Applications directory. Applications inside that directory doesn't have any restrictions by default and can access any private API.

这篇关于使用私有 API 在 iOS 7 上扫描网络 (SSID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用私有 API 在 iOS 7 上扫描网络 (SSID)

基础教程推荐