読者です 読者をやめる 読者になる 読者になる

DELAEMON BLOG

Live as if you were to die tomorrow. Learn as if you were to live forever.

Mac OSX EI Capitan Wifi Commands

Mac Bookのネットワーク接続(Wifi/Proxy)をターミナルからコマンドから操作したい。

OS version

OS X EI Capitan

Wifiの操作
# On
$ networksetup -setairportpower en0 on

# Off
$ networksetup -setairportpower en0 off

# Info
$ networksetup -getairportnetwork en0

# SSIDの一覧表示
$ sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s

# 任意のネットワークに接続
$ sudo networksetup -setairportnetwork en0 <ssid> <password>
Proxyの操作
# On
$ sudo networksetup -setwebproxystate Wi-Fi on; sudo networksetup -setsecurewebproxystate Wi-Fi on

# Off
$ sudo networksetup -setwebproxystate Wi-Fi off; sudo networksetup -setsecurewebproxystate Wi-Fi off

# Info
$ networksetup -getwebproxy Wi-Fi; networksetup -getsecurewebproxy Wi-Fi
エイリアスに設定
alias wifi-on='networksetup -setairportpower en0 on'
alias wifi-off='networksetup -setairportpower en0 off'
alias wifi-info='networksetup -getairportnetwork en0'
alias proxy-on='sudo networksetup -setwebproxystate Wi-Fi on; sudo networksetup -setsecurewebproxystate Wi-Fi on'
alias proxy-off='sudo networksetup -setwebproxystate Wi-Fi off; sudo networksetup -setsecurewebproxystate Wi-Fi off'
alias proxy-info='networksetup -getwebproxy Wi-Fi; networksetup -getsecurewebproxy Wi-Fi'
alias airport='sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
実際に打ってるコマンド
$ proxy-on && wifi-on
$ proxy-off && wifi-off
$ proxy-info && wifi-info