开发者

Getting OSX Connected Wi-Fi Network Name

开发者 https://www.devze.com 2023-02-05 08:40 出处:网络
I need to get the name of the currently connected Wi-Fi SSID on OSX. I\'ve messed 开发者_开发知识库with the SystemConfiguration framework, I feel like it is there (as I am able to get the name of the

I need to get the name of the currently connected Wi-Fi SSID on OSX.

I've messed 开发者_开发知识库with the SystemConfiguration framework, I feel like it is there (as I am able to get the name of the network locaiton) but I am not really finding a way of getting the Wi-Fi SSID.

Would appreciate any help. :)

Thanks.


For osX Yosemite 10.10 use

#import <CoreWLAN/CoreWLAN.h>

-(void)prettyFunctionName
{
  CWInterface* wifi = [[CWWiFiClient sharedWiFiClient] interface];

  NSLog(@"BSD if name: %@", wifi.interfaceName);
  NSLog(@"SSID: %@", wifi.ssid);
  NSLog(@"txRate: %f", wifi.transmitRate);
}


You can use the CoreWLAN framework: CWInterface has a property called ssid. The code below gets the current wireless interface and shows its BSD name and its SSID. It works on Mac OS 10.6+.

#import <Foundation/Foundation.h>
#import <CoreWLAN/CoreWLAN.h>

int main() {
    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    CWInterface *wif = [CWInterface interface];

    NSLog(@"BSD if name: %@", wif.name);
    NSLog(@"SSID: %@", wif.ssid);

    [pool drain];
    return 0;
}

Output:

$ ./wif
BSD if name: en1
SSID: Aetherius
0

精彩评论

暂无评论...
验证码 换一张
取 消