Reputation: 3063
I am trying to get BSSID of current WiFi connection on Mac OS X 10.14 but get nil
.
The code returning nil
is the following:
NSString *bssid = [[[CWWiFiClient sharedWiFiClient] interface] bssid];
though SSID returns valid value:
NSString *ssid = [[[CWWiFiClient sharedWiFiClient] interface] ssid];
Other solutions works for iOS, e.g. using CaptiveNetworks framework proposed here How do I get the current access point's MAC address/BSSID?, but some methods, like CNCopyCurrentNetworkInfo
- not supported for MacOS.
Upvotes: 0
Views: 1542
Reputation: 3063
This is not the best solution, but at least it works in Qt:
QString getBssidOnMac() {
QStringList arguments;
arguments << "-I";
QProcess process;
process.start("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport", arguments);
process.waitForFinished();
QString outp = process.readAllStandardOutput();
QRegExp re_bssid(".*(BSSID\\:\\s([0-9a-fA-F]{1,2}(\\:[0-9a-fA-F]{1,2}){5})).*");
if (re_bssid.indexIn(outp) !=-1) {
return re_bssid.cap(2);
}
else {
return QString();
}
}
Upvotes: 2
Reputation: 11646
my two cents for OSX, in case:
Call:
let client = CWWiFiClient.shared()
guard let interfaces : [CWInterface] = client.interfaces() else{
return nil
}
// on iOS we got the first, here we should return multiple interfaces.
var ssid: String?
var bssid: String?
var interfaceNameString: String?
for interface in interfaces{
ssid = interface.ssid()
bssid = interface.bssid()
interfaceNameString = interface.interfaceName
...
}
be careful to activate:
if on App Store for OSX, when activating Sandboxing.
Upvotes: 1