【发布时间】:2017-07-17 17:45:30
【问题描述】:
我正在尝试在 Mac 上以编程方式连接到特定的 wifi 网络。我找到了this document
使用 'airport' 对我不起作用,所以我使用命令列出接口:
$ /usr/sbin/networksetup -listnetworkserviceorder
An asterisk (*) denotes that a network service is disabled.
(1) Bluetooth DUN
(Hardware Port: Bluetooth DUN, Device: Bluetooth-Modem)
(2) USB Ethernet
(Hardware Port: USB Ethernet, Device: en3)
(3) Display Ethernet
(Hardware Port: Display Ethernet, Device: en5)
(4) Display FireWire
(Hardware Port: Display FireWire, Device: fw0)
(5) Wi-Fi
(Hardware Port: Wi-Fi, Device: en0)
(6) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en4)
(7) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)
然后我跑了:
$ /usr/sbin/networksetup -setairportnetwork en0 Internet
Failed to join network Internet.
Error: -3905 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3905.)Failed to join network Internet.
Error: -3905 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3905.)Failed to join network Internet.
Error: -3905 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3905.)Failed to join network Internet.
Error: -3905 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3905.)Failed to join network Internet.
Error: -3905 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3905.)Failed to join network Internet.
Error: -3905 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3905.)Failed to join network Internet.
Error: 82 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error 82.)Failed to join network Internet.
Error: -3903 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3903.)Failed to join network Internet.
Error: -3903 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3903.)Failed to join network Internet.
Error: -3903 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3903.)Failed to join network Internet.
Error: -3903 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3903.)
我可以在“处理”模式下看到托盘上的wifi图标很长一段时间。
手动点击同一个托盘图标并点击网络确实成功连接到网络。
如何在 Mac 上以编程方式连接到 wifi 网络?
【问题讨论】:
-
你确定需要
/usr/sbin/networksetup -setairportnetwork en0 Internet PASSWORD? -
@MarkSetchell 就是这样。由于在通过 UI 选择网络时不需要重新输入已知网络的密码,因此我没想到必须提供密码明文作为命令行参数。您可以添加您的评论作为答案吗?
标签: macos networking wifi