Mac OS X: bash脚本实现添加无线SSID(Update2009-10-09)

Mac OS X: shell程序实现添加无线SSID

 

 


2009-10-08:

 

 

一个基本的实现脚本, 没有重复/删除/错误检查等处理:

yourSSID="TEST"
yourPWD="TEST"
SecurityType="WEP"
WEPOpenSystem=true
networkUUID=`uuidgen`
pwdUUID=`uuidgen`
cTime=`date "+%a %b %e %H:%M:%S %Z %Y"`
function addSSID_Airport_Pref 
{
	# plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "print KnownNetworks"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "add KnownNetworks:$networkUUID dict"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "add KnownNetworks:$networkUUID:SecurityType string $SecurityType"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "add KnownNetworks:$networkUUID:SSID_STR string $yourSSID"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "add KnownNetworks:$networkUUID:'Unique Password ID' string $pwdUUID"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "add KnownNetworks:$networkUUID:'Remembered channels' array {0 integer 1}"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "add KnownNetworks:$networkUUID:_timeStamp date $cTime"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "add KnownNetworks:$networkUUID:WEPOpenSystem bool $WEPOpenSystem"
#	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "print KnownNetworks:$networkUUID"
}
function addPWD_SystemKeychain
{
#	default_keychain = `security default-keychain`
	security default-keychain -s /Library/Keychain/System.keychain
	sudo security add-generic-password -a "$yourSSID" -D "AirPort network password" -s "$pwdUUID" -l "$yourSSID" -w "$yourPWD" -j "wireless_setup_v1.0" -A -U
#	security default-keychain -s $default_keychain
	security default-keychain -s ""
}
function addLocation
{
	currentSet=`plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "print CurrentSet"`
#	currentSet=${currentSet:6}
	currentSet=${currentSet/":"}
	
#	plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "print $currentSet:Network:Interface:en1:AirPort:PreferredNetworks"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "add $currentSet:Network:Interface:en1:AirPort:PreferredNetworks:0 dict"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "add $currentSet:Network:Interface:en1:AirPort:PreferredNetworks:0:SSID_STR string $yourSSID"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "add $currentSet:Network:Interface:en1:AirPort:PreferredNetworks:0:SecurityType string 'WEP'"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "add $currentSet:Network:Interface:en1:AirPort:PreferredNetworks:0:'Unique Newtork ID' string $networkUUID"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "add $currentSet:Network:Interface:en1:AirPort:PreferredNetworks:0:'Unique Password ID' string $pwdUUID"
	sudo plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "set $currentSet:Network:Interface:en1:AirPort:RequireAdmin bool No"
#	plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "print $currentSet:Network:Interface:en1:AirPort:PreferredNetworks:0"
}
function CleanAll
{
# 1. Delete from preferences.plist
	currentSet=`plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "print CurrentSet"`
	currentSet=${AA/":"}
	sudo plistbuddy /Library/Preferences/SystemConfiguration/preferences.plist -c "delete $currentSet:Network:Interface:en1:AirPort:PreferredNetworks:0"
#2. Delete Airport_Pref
	sudo plistbuddy /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist -c "delete KnownNetworks:$networkUUID"
#3. Delete Keychain
	security default-keychain -s /Library/Keychain/System.keychain
	sudo security add-generic-password -a "$yourSSID" -D "AirPort network password" -s "$pwdUUID" -l "$yourSSID" -w "$yourPWD" -j "wireless_setup_v1.0" -A -U
	security default-keychain -s ""
}
ln -f /usr/libexec/PlistBuddy /usr/sbin/plistbuddy
addSSID_Airport_Pref 
addPWD_SystemKeychain
addLocation
logger "Wireless addition finished successfully."

 

 


2009-10-07

 

这个bash脚本用于企业内部规模部署的时候,无须为了添加无线网络到系统核心影像文件中而设计。

 

正在编写,成功可能性还是有的, 基本条件已经具备了.

 


原文链接: http://blog.csdn.net/afatgoat/article/details/4640818

转载于:https://my.oschina.net/junwong/blog/46509

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值