Hi all,
My scripting skills are slowly improving, but I am in need of some assistance. I need to block our guest network that has a hyphen in the SSID. I found this awesome script here on Jamfnation. Obviously, it works well with non hyphenated SSID's. Does anyone know how to properly convert the the hyphenated variable and where to place it within the script? I have not been able to find a clear answer in my research.
!/bin/bash
Blocks access to Guest network
VARIABLES
Get the wireless network service (wservice)
wservice=/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(Wi-Fi|AirPort)'
Get the wireless hardware port (whwport)
whwport=networksetup -listallhardwareports | awk "/$wservice/,/Ethernet Address/" | awk 'NR==2' | cut -d " " -f 2
Find the ALL network hardware ports (hwports)
hwports=networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/,/Ethernet/' | awk 'NR==2' | cut -d " " -f 2
Get the wireless network (wirelessnw)
wirelessnw=networksetup -getairportnetwork $hwports | cut -d " " -f 4
Get the SSID
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I
| grep ' SSID:' | cut -d ':' -f 2 | tr -d ' '`
Work SSID
WorkSSID=XXXXXXX
Authentication to use eg WPA2 Enterprise
Auth=WPA2E
Index for SSID
Index=0
SSIDs to Block
Block1=BLAH-BYOD
########################################################################
Set the preferred wireless network to WorkSSID
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex $whwport $WorkSSID $Index $Auth
Turn the wirless hardware port on
/usr/sbin/networksetup -setairportpower $whwport on
Get the wireless network (wirelessnw)
wirelessnw=networksetup -getairportnetwork $hwports | cut -d " " -f 4
Block wireless networks
case $wirelessnw in
XXXXXX)
networksetup -setairportpower $whwport off
Removed guest network from preferred network list to prevent endless looping
/usr/sbin/networksetup -removepreferredwirelessnetwork $whwport XXXXXX
Display message to user connect to Corp WIFI
TITLE="Access Denied"
MSG="Please turn on Wi-Fi connect to CORP WIFI"
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "$TITLE" -description "$MSG" -button1 "Close" -lockHUD -icon /Library/LC/Logo.icns
;;
esac
Check to see it the jss is ping-able and if so submit the ip change to the jss.
This is useful when using Casper Remote and users are switching between wired and wireless
if [ "$checkjss" == "The JSS is available." ]; then
/usr/sbin/jamf log
fi
exit 0