VGHTC Wireless Auto-login for Mac OS X

每次筆電從休眠狀態復原,連上網路後,總要重新輸入 web authentication,用鍵盤輸入是不用花多少時間,但在智慧型手機上就很令人厭煩,於是先找了一個 WLanLogin 的 App,找出 VGHTC 的登入網址和參數,測試成功後,果然方便許多。回過頭來想,如果筆電也能自動登入,那不也很方便嗎?所以參考了這篇 For NTNU 的設定,修改為 VGHTC 的版本:

環境: Mac OS X 10.6.8

設定 LaunchAgent

~/Library/LaunchAgents/LocationChanger.plist





    Label
    tech.inhelsinki.nl.locationchanger
    ProgramArguments
    
        /Users/USERNAME/bin/locationchanger
    
    WatchPaths
    
        /Library/Preferences/SystemConfiguration
    


登入用 Script

  1. ~/bin/locationchanger (如下)
  2. chmod 755 ~/bin/locationchanger
  3. 用 MacPorts 裝 wget
#!/bin/bash
# automatically change configuration of Mac OS X based on location
# author: Onne Gorter
# modified: Reverb CS Chu
# original-url: http://tech.inhelsinki.nl/locationchanger/
# version: 0.4.1
USERNAME="帳號"
PASSWORD="密碼"
# redirect all IO to /dev/null (comment this out if you want to debug)
exec 1>/dev/null 2>/dev/null
# get a little breather before we get data for things to settle down
sleep 2
# get various system information
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep ' SSID:' | cut -d ':' -f 2 | tr -d ' '`
if [ $SSID == "VGHTCAP" ]; then
    POSTLOGIN="buttonClicked=4&username=$USERNAME&password=$PASSWORD"
    /opt/local/bin/wget -O- http://172.23.253.249/cgi-bin/login --post-data=$POSTLOGIN -T2 -t2
fi
exit 0

載入設定檔

  1. 重新開機或是手動載入
  2. launchctl load ~/Library/LaunchAgents/LocationChanger.plist