さらに、同時に使うことがあるコマンド、「aiport -I, airporl -s」も簡単に呼び出せるようにしました。Mavericksでこのスクリプトを制作して重宝していました。
残念なことにYosemiteで動作不良が起こったので、それを修正しました。Yosemiteではネットワーク環境が大幅に変更される模様ですので、このスクリプトを紹介します。
ターミナルでの実施例
スクリプトのソース
#!/bin/zsh
# we: "Wifi state Exchanger" script for Yosemite
# Usage:
# • we⏎ : normal opration: exchange state(on/off) of Wi-Fi.
# • we n⏎: normal operation with no output.
# • we i⏎: airport -I
# • we s⏎: airport -s
# 2015-04-15 11:12:27 from won/wof, by mNeji.
# variables
local Pctrol a api apa inp etp
local pre_status chg_status
local my_initial my_now nsec cen1
# input parameter
Pctrol="$1"
# direct definition to the command 'airport' for general purose
a="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/"
a=${a}Current/Resources/airport
# airport call & finish
if [[ "$Pctrol" = "i" ]]; then
$a -I; return
elif [[ "$Pctrol" = "s" ]]; then
$a -s; return
fi
# set status for previous and changed
pre_status=$([[ "$(ipconfig getifaddr en1 )" = "" ]] && echo "off" || echo "on")
#echo $pre_status
[[ "$pre_status" = "off" ]] && chg_status="on" || chg_status="off"
#echo $pre_status
#echo $chg_status
# Change Airport status
networksetup -setairportpower en1 $chg_status
# set initial date in unit of 'sec'
my_initial=$(date +%s)
# main waiting loop until 'netstat' contain en1 conpornents.
while : ; do
my_now=$(date +%s)
nsec=$(($my_now-$my_initial))
if [[ "$Pctrol" = "" ]]; then
printf "\rWi-Fi:$pre_status → passed(sec): %d" $nsec
fi
cen1=$(netstat -r -f inet | grep en1)
# s=$(ipconfig getifaddr en1) # it was worked at Mavericks.
[[ "$cen1" = "" ]] && continue || break
done
if [[ "$Pctrol" = "" ]]; then
echo -n "\rWi-Fi[$pre_status→(${nsec}sec)→$chg_status] "
fi
# list up status for wifi
api=$($a -I |grep "^ *SSID: " |sed 's/^ *//g' |cut -d' ' -f2)
apa=$($a -I |grep "^ *BSSID: " |sed 's/^ *//g' |cut -d' ' -f2)
inp=$(ifconfig en1 | grep 'inet ' | cut -d' ' -f2)
etp=$(ifconfig en1 | grep ether | cut -d' ' -f2)
if [[ "$Pctrol" = "" ]]; then
if [[ "$chg_status" = "on" ]]; then
echo "$api($apa)⥢⥤ $inp($etp)"
else
echo "AccessPoint is idle."
fi
fi
____ このページの履歴
- 開始 2015-04-16(木) 20:04:55
- 修正 2015-04-17(金) 00:32:09 図の修正

0 件のコメント:
コメントを投稿