Skip to content

Instantly share code, notes, and snippets.

@fqrouter
Last active December 14, 2015 03:39
Show Gist options
  • Save fqrouter/5022480 to your computer and use it in GitHub Desktop.
Save fqrouter/5022480 to your computer and use it in GitHub Desktop.
int Apple80211Associate(struct Apple80211 *handle, CFDictionaryRef *network, CFString *wpa_key);
gcc -Wall -Os -framework Foundation -framework CoreFoundation main.c -o net
#include <dlfcn.h>
#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
int main() {
void *handle = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);
int (*open)(void *) = dlsym(handle, "Apple80211Open");
int (*bind)(void *, CFStringRef) = dlsym(handle, "Apple80211BindToInterface");
int (*close)(void *) = dlsym(handle, "Apple80211Close");
int (*scan)(void *, CFArrayRef *, void *) = dlsym(handle, "Apple80211Scan");
void *airportHandle;
open(&handle);
bind(handle, CFSTR("en0"));
CFDictionaryRef parameters = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFArrayRef networks;
scan(handle, &networks, parameters);
int i;
for (i = 0; i < CFArrayGetCount(networks); i++) {
CFDictionaryRef network = CFArrayGetValueAtIndex(networks, i);
CFShow(CFDictionaryGetValue(network, CFSTR("BSSID")));
}
close(handle);
dlclose(handle);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment