Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS get current wlan network name

I am looking for a way to obtain information (at least the name) of the current connected wlan network in objective-c for iOS5.

I need this because we are currently developing an application that do not work in a particular network. In this network (on our university) the port is closed that we need to connect to the server. But there is another network also available and we want to tell the user that he has to switch the network if he is connected to the aforementioned one.

I do not even know where to start. Does anyone have an idea or any hints?

Thanks and regards

like image 781
Chris Avatar asked Jun 10 '12 09:06

Chris


People also ask

How do I find my WiFi network name on my iPhone?

An SSID is the name of a WiFi network. So if you are looking for the SSID for the WiFi network you are connected to on your iPhone, you will go to Settings > WiFi and there you will see the name (or SSID) of the network.

How do I find my WLAN name?

You can likely find your router's default network name, or SSID, on a sticker on the back or side of the router. It may also appear in the router's manual.

How can I get a list of available Wi-Fi networks from iOS app?

To do this, open System Preferences, and then click Network. Select Wi-Fi in the sidebar, and then click Advanced. In the Wi-Fi tab, you will see a list of networks. This list is mainly there so you can choose an order of preference for joining networks.


2 Answers

From iOS >= 4.1 it's possible to obtain SSID of wireless network that device is currenctly connected to.

For this you'd use function CNCopyCurrentNetworkInfo

Details on implemenation are available on SO: iPhone get SSID without private library

like image 58
Rok Jarc Avatar answered Oct 06 '22 03:10

Rok Jarc


It is possible to get the current wifi information from the Captive Network. In the past, apple actually disabled this for a while, but they seems to re-enabled it due to strong request. It is also possible that they decide to close this in the future.

The information we can get is BSSID, SSID, SSIDDATA. BSSID is the unique address for wifi, SSID is the current wifi name, SSIDDATA is the hex representation for the SSID.

For Swift 3.1:

func printCurrentWifiInfo() {
  if let interface = CNCopySupportedInterfaces() {
    for i in 0..<CFArrayGetCount(interface) {
      let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interface, i)
      let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
      if let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString), let interfaceData = unsafeInterfaceData as? [String : AnyObject] {
        // connected wifi
        print("BSSID: \(interfaceData["BSSID"]), SSID: \(interfaceData["SSID"]), SSIDDATA: \(interfaceData["SSIDDATA"])")
      } else {
        // not connected wifi
      }
    }
  }
}

For Objective-C

NSArray *interFaceNames = (__bridge_transfer id)CNCopySupportedInterfaces();

for (NSString *name in interFaceNames) {
  NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)name);

  NSLog[@"wifi info: bssid: %@, ssid:%@, ssidData: %@", info[@"BSSID"], info[@"SSID"], info[@"SSIDDATA"]];
}
like image 28
nuynait Avatar answered Oct 06 '22 01:10

nuynait