Getting OSX Connected Wi-Fi Network Name
Asked Answered
H

2

10

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.

Hedve answered 19/1, 2011 at 21:24 Comment(0)
W
10

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
Writing answered 19/1, 2011 at 21:58 Comment(4)
Seems great. Will test as soon as I get home.Hedve
What if you have a ethernet connection then? I suppose the WLANInterface wont work for that (obviously), so what then? :)Firebox
In OS 10.10 [CWInterface interface] has been deprecated. Anyone have ideas for what to use instead?Caerleon
@Caerleon clang says you should use -[CWWiFiClient interface], however I can't find any documentation for it and the class doesn't seem to exist in CoreWLAN framework. So I would just use +[CWInterface interface] anyway.Roseboro
T
12

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);
}
Tannie answered 15/1, 2015 at 17:8 Comment(1)
Thanks I've been looking for this :)Corral
W
10

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
Writing answered 19/1, 2011 at 21:58 Comment(4)
Seems great. Will test as soon as I get home.Hedve
What if you have a ethernet connection then? I suppose the WLANInterface wont work for that (obviously), so what then? :)Firebox
In OS 10.10 [CWInterface interface] has been deprecated. Anyone have ideas for what to use instead?Caerleon
@Caerleon clang says you should use -[CWWiFiClient interface], however I can't find any documentation for it and the class doesn't seem to exist in CoreWLAN framework. So I would just use +[CWInterface interface] anyway.Roseboro

© 2022 - 2024 — McMap. All rights reserved.