日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

IOS零碎技术整理(3)-获取wifi列表

發(fā)布時(shí)間:2024/4/17 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS零碎技术整理(3)-获取wifi列表 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.?? 該功能實(shí)現(xiàn)基于MobileApple80211框架來(lái)進(jìn)行開(kāi)發(fā),而目前該框架成為了私有框架,其中的API均為私有API。

如果使用這些API可能導(dǎo)致應(yīng)用不能上app store或者ios版本升級(jí)過(guò)程中,可能對(duì)私有api不兼容,導(dǎo)致程序莫名的掛掉或數(shù)據(jù)獲取失敗

2.?? 終端必須越獄,且必須把程序部署到終端的/Applications目錄下取得超級(jí)用戶權(quán)限才能獲得wifi的訪問(wèn)權(quán)限

代碼

#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];

}

@end

轉(zhuǎn)載于:https://www.cnblogs.com/v-jing/p/3302887.html

總結(jié)

以上是生活随笔為你收集整理的IOS零碎技术整理(3)-获取wifi列表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。