import Cocoa
import CoreWLAN
class Discovery {
var currentInterface: CWInterface
var interfacesNames: [String] = []
var networks: Set = []
// Failable init using default interface
init?() {
if let defaultInterface = CWWiFiClient.shared().interface(),
let name = defaultInterface.interfaceName {
self.currentInterface = defaultInterface
self.interfacesNames.append(name)
self.findNetworks()
} else {
return nil
}
}
// Init with the literal interface name, like "en1"
init(interfaceWithName name: String) {
self.currentInterface = CWInterface(interfaceName: name)
self.interfacesNames.append(name)
self.findNetworks()
}
// Fetch detectable WIFI networks
func findNetworks() {
do {
self.networks = try currentInterface.scanForNetworks(withSSID: nil)
} catch let error as NSError {
print("Error: \(error.localizedDescription)")
}
}
// Fetch current connected wifi network
func getCurrentConnectedWifiNetwork() -> [String: Any] {
var currentNetwork: [String: Any] = [:]
currentNetwork["ssid"] = currentInterface.ssid()
currentNetwork["security"] = currentInterface.security().rawValue
currentNetwork["channelNumber"] = currentInterface.wlanChannel()?.channelNumber
currentNetwork["IPAddress"] = getIPAddress(interfaceName: currentInterface.interfaceName!)
currentNetwork["rssi"] = currentInterface.rssiValue()
return currentNetwork
}
I have created the "Discovery" class to get the connected wifi network details (SSID, Security, Channel Number, IPAddress, RSSI) and From viewController calling the below function.
if let discoveryObject = Discovery() {
let currentConnectedWifi = discoveryObject.getCurrentConnectedWifiNetwork()
print("\nConnected wifi network: \n\n\(currentConnectedWifi)\n")
}
The console log for the network "NETGEAR10" (not a guest wifi network)
["channelNumber": 13, "IPAddress": "192.168.1.4", "security": 4, "ssid": "NETGEAR10", "rssi": -36]
Now, created a guest wifi network name as "NETGEAR_Guest" and the details are,
["rssi": -38, "channelNumber": 13, "ssid": "NETGEAR_Guest", "security": 4, "IPAddress": "192.168.1.4"]
I need to know what exact metadata is available to identify the guest network in CoreWLAN andhelp is much needed. Thank you.