找回密码
 立即注册
1.这个功能的开发是基于MobileApple80211框架,现在是私有框架,里面的API都是私有API。

如果使用这些API,可能会导致应用无法在应用商店上架或ios版本升级过程与私有API不兼容,导致程序莫名挂起或数据获取失败

2.终端必须越狱,程序必须部署到终端的/Applications目录下才能获得超级用户权限才能访问wifi

代码

#import <Foundation/Foundation.h>

#import <CoreFoundation/CoreFoundation.h>

#include <dlfcn.h>

@interface SOLStumbler : NSObject {
    NSMutableDictionary *networks; //Key: MAC Address (BSSID)

   

    void *libHandle;

    void *airportHandle;

    int (*apple80211Open)(void *);

    int (*apple80211Bind)(void *, NSString *);

    int (*apple80211Close)(void *);

    int (*associate)(void *, NSDictionary*, NSString*);

    int (*apple80211Scan)(void *, NSArray **, void *);

}

- (NSDictionary *)networks;                                                             //returns all 802.11 scanned network(s)

- (NSDictionary *)network:(NSString *) BSSID;                   //return specific 802.11 network by BSSID (MAC Address)

- (void)scanNetworks;

- (int)numberOfNetworks;

@end



#import "SOLStumbler.h"



@implementation SOLStumbler



- (id)init

{
    self = [super init];

   

    networks = [[NSMutableDictionary alloc] init];

    libHandle = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);

    char *error;

    if (libHandle == NULL && (error = dlerror()) != NULL)  {
       NSLog(@">>>  error %s",error);

       exit(1);

    }

    apple80211Open = dlsym(libHandle, "Apple80211Open");

    apple80211Bind = dlsym(libHandle, "Apple80211BindToInterface");

    apple80211Close = dlsym(libHandle, "Apple80211Close");

    apple80211Scan = dlsym(libHandle, "Apple80211Scan");

    apple80211Open(&airportHandle);

    apple80211Bind(airportHandle, @"en0");

    return self;

}



- (NSDictionary *)network:(NSString *) BSSID

{
    return [networks objectForKey:@"BSSID"];

}



- (NSDictionary *)networks

{
    return networks;

}



- (void)scanNetworks

{
    NSLog(@"Scanning WiFi Channels...");

   

    NSDictionary *parameters = [[NSDictionary alloc] init];

    NSArray *scan_networks; //is a CFArrayRef of CFDictionaryRef(s) containing key/value data on each discovered network

    apple80211Scan(airportHandle, &scan_networks, parameters);

    NSLog(@"===-scan_networks-======%@",scan_networks);

    for (int i = 0; i < [scan_networks count]; i++) {
       [networks setObject:[scan_networks objectAtIndex: i] forKey:[[scan_networks objectAtIndex: i] objectForKey:@"BSSID"]];

    }

    NSLog(@"Scanning WiFi Channels Finished.");

}



- (int)numberOfNetworks

{
    return [networks count];

}



- ( NSString * ) description {
    NSMutableString *result = [[NSMutableString alloc] initWithString:@"Networks State: \n"];

    for (id key in networks){
       [result appendString:[NSString stringWithFormat:@"%@ (MAC: %@), RSSI: %@, Channel: %@ \n",

                            [[networks objectForKey: key] objectForKey:@"SSID_STR"], //Station Name

                            key, //Station BBSID (MAC Address)

                            [[networks objectForKey: key] objectForKey:@"RSSI"], //Signal Strength

                            [[networks objectForKey: key] objectForKey:@"CHANNEL"]  //Operating Channel

                            ]];

    }

    return [NSString stringWithString:result];

}



- (void) dealloc {
    apple80211Close(airportHandle);

    [super dealloc];

}

(1. The development of this function is based on the mobileapple80211 framework. Now it is a private framework, and the APIs in it are private APIs.
If these APIs are used, the application may not be available in the app store, or the IOS version upgrade process is incompatible with the private API, resulting in program suspension or data acquisition failure
2. The terminal must escape from prison, and the program must be deployed to the / applications directory of the terminal to obtain super user permission and access WiFi
code
#import <Foundation/Foundation. h>
#import <CoreFoundation/CoreFoundation. h>
#include <dlfcn. h>
@interface SOLStumbler : NSObject {
NSMutableDictionary *networks; // Key: MAC Address (BSSID)
void *libHandle;
void *airportHandle;
int (*apple80211Open)(void *);
int (*apple80211Bind)(void *, NSString *);
int (*apple80211Close)(void *);
int (*associate)(void *, NSDictionary*, NSString*);
int (*apple80211Scan)(void *, NSArray **, void *);
}
- (NSDictionary *)networks;                                                             // returns all 802.11 scanned network(s)
- (NSDictionary *)network:(NSString *) BSSID;                   // return specific 802.11 network by BSSID (MAC Address)
- (void)scanNetworks;
- (int)numberOfNetworks;
@end
#import "SOLStumbler.h"
@implementation SOLStumbler
- (id)init
{
self = [super init];
networks = [[NSMutableDictionary alloc] init];
libHandle = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);
char *error;
if (libHandle == NULL && (error = dlerror()) !=  NULL)  {
NSLog(@">>>  error %s",error);
exit(1);
}
apple80211Open = dlsym(libHandle, "Apple80211Open");
apple80211Bind = dlsym(libHandle, "Apple80211BindToInterface");
apple80211Close = dlsym(libHandle, "Apple80211Close");
apple80211Scan = dlsym(libHandle, "Apple80211Scan");
apple80211Open(&airportHandle);
apple80211Bind(airportHandle, @"en0");
return self;
}
- (NSDictionary *)network:(NSString *) BSSID
{
return [networks objectForKey:@"BSSID"];
}
- (NSDictionary *)networks
{
return networks;
}
- (void)scanNetworks
{
NSLog(@"Scanning WiFi Channels...");
NSDictionary *parameters = [[NSDictionary alloc] init];
NSArray *scan_ networks; // is a CFArrayRef of CFDictionaryRef(s) containing key/value data on each discovered network
apple80211Scan(airportHandle, &scan_networks, parameters);
NSLog(@"===-scan_networks-======%@",scan_networks);
for (int i = 0; i < [scan_networks count]; i++) {
[networks setObject:[scan_networks objectAtIndex: i] forKey:[[scan_networks objectAtIndex: i] objectForKey:@"BSSID"]];
}
NSLog(@"Scanning WiFi Channels Finished.");
}
- (int)numberOfNetworks
{
return [networks count];
}
- ( NSString * ) description {
NSMutableString *result = [[NSMutableString alloc] initWithString:@"Networks State: \n"];
for (id key in networks){
[result appendString:[NSString stringWithFormat:@"%@ (MAC: %@), RSSI: %@, Channel: %@ \n",
[[networks objectForKey: key] objectForKey:@"SSID_STR"], //Station Name
key, //Station BBSID (MAC Address)
[[networks objectForKey: key] objectForKey:@"RSSI"], //Signal Strength
[[networks objectForKey: key] objectForKey:@"CHANNEL"]  //Operating Channel
]];
}
return [NSString stringWithString:result];
}
- (void) dealloc {
apple80211Close(airportHandle);
[super dealloc];
}
)





上一篇:在 ECLIPSE 中导入 DTD 和 XSD 文件以使 XML 自动提示
下一篇:ANDROID开发------ACTIVITY生命周期