atlascoder
atlascoder

Reputation: 3063

can't get actual bssid value on MacOS

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

Answers (2)

atlascoder
atlascoder

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

ingconti
ingconti

Reputation: 11646

my two cents for OSX, in case:

  • Use CoreWLAN
  • Add NetworkExtensions
  • 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:

enter image description here

if on App Store for OSX, when activating Sandboxing.

Upvotes: 1

Related Questions