How would I go about creating a wireless adhoc network with a specified SSID and password on OS X? I tried looking at the networksetup
man page but didn't come up with anything to accomplish this. Is there another command I should be using?
In OSX 10.13, I had to modify @dan-ramos 's code to:
import Foundation
import CoreWLAN
let networkName = "foo"
let password = "bar"
if let iface = CWWiFiClient.shared().interface() {
do {
try iface.startIBSSMode(
withSSID: networkName.data(using: String.Encoding.utf8)!,
security: CWIBSSModeSecurity.WEP104,
channel: 11,
password: password as String
)
print("Success")
} catch let error as NSError {
print("Error", error)
exit(1)
}
} else {
print("Invalid interface")
exit(1)
}
I didn't find any real way to do it other than to write a Swift script:
import Foundation
import CoreWLAN
var networkName = "foo";
var password = "bar";
var error: NSError?
let iface = CWWiFiClient.sharedWiFiClient().interface()
let success = iface.startIBSSModeWithSSID(
networkName.dataUsingEncoding(NSUTF8StringEncoding),
security: CWIBSSModeSecurity.WEP104,
channel: 11,
password: password as String,
error: &error
)
if !success {
println(error?.localizedDescription)
} else {
NSRunLoop.currentRunLoop().run()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With