I was wondering if someone ca help me with variable for all the SSIDs.
so far this works
#!/bin/sh
# Prevent Access to RLSPOT001
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I
| grep ' SSID:' | cut -d':'-f2 | tr -d' '`
if [ $SSID = "RLSPOT001" ]; then
/usr/sbin/networksetup -setairportpower en1 off
fi# Prevent Access to RLAVID001
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I
| grep ' SSID:' | cut -d':'-f2 | tr -d' '`
if [ $SSID = "RLAVID001" ]; then
/usr/sbin/networksetup -setairportpower en1 off
fi# Prevent Access to RLSHEE001
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I
| grep ' SSID:' | cut -d':'-f2 | tr -d' '`
if [ $SSID = "RLSHEE001" ]; then
/usr/sbin/networksetup -setairportpower en1 off
fi# Prevent Access to RLGUES001
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I
| grep ' SSID:' | cut -d':'-f2 | tr -d' '`
if [ $SSID = "RLGUES001" ]; then
/usr/sbin/networksetup -setairportpower en1 off
fi# Prevent Access to RLBGAS001
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I
| grep ' SSID:' | cut -d':'-f2 | tr -d' '`
if [ $SSID = "RLBGAS001" ]; then
/usr/sbin/networksetup -setairportpower en1 off
fi# open networks control# Prevent Access to BTFON
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I
| grep ' SSID:' | cut -d':'-f2 | tr -d' '`
if [ $SSID = "BTFON" ]; then
/usr/sbin/networksetup -setairportpower en1 off
fi
As you can see it makes my whole script very long.
I would appreciated if someone might be able to help me to create a variable for all of them
Best answer by tkimpton
Thanks Jared i just got round to adding in your variables and this is what i am using now :)
#!/bin/bash################################################################################################################################################## HISTORY## Version: 2.8## - Created by Tim Kimpton on November 29th, 2012# - Assisted by Jared Nichols and Mike from JAMFNATION to clean up and simplify the blocked ssid case statement and network interface variables## Stops network bridging turning the relevant network interface off and on################################################################################################################################################## SETTING THE ENVIRONMENT VARIABLES# Get the ethernet hardware port (ehwport)
ehwport=`networksetup -listallhardwareports | awk '/.Ethernet/,/Ethernet Address/' | awk 'NR==2' | cut -d " " -f 2`
# 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 ' '`
# Current Logged in User
consoleuser=`ls -l /dev/console | cut -d " " -f4`
# Carry out an OS version check
OS=`/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'`
# Work SSID
WorkSSID=XXX
# Authentication to use eg WPA2 Enterprise
Auth=WPA2E
# Index for SSID
Index=0# Check to see if the JSS is available and if yes, then submits the current IP
checkjss=`/usr/sbin/jamf checkJSSConnection -retry 0 | grep "The JSS is available"`
# Department allowed to bypass SSID restrictions
Dept=XXX
# SSIDs to Block
Block1=XXX
Block2=XXX
Block3=XXX
Block4=XXX
##################################################################################### See if ethernet if active and if it is then we need to turn OFF the wirelesss interface!if ifconfig "${ehwport}" | grep inet; then
/usr/sbin/networksetup -setairportpower $whwport off# There is also a bug where wireless network interfaces are caching DNS and causes problems when switching networks, so we need to clear them!
/usr/sbin/networksetup -setdnsservers $wservice "empty"# if Ethernet is not active then...
elif ifconfig "${ehwport}" | grep inactive; then# Clear the DNS cache for the wireless network service
/usr/sbin/networksetup -setdnsservers $wservice "empty"# Do not ask to join new networks
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs joinmode=automatic joinmodefallback=donothing
# 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
fi
# Prevent 169 IP Address problem for Work SSIDif [ $SSID = $WorkSSID ]; thenif ifconfig "${whwport}" | grep 169;
then# If APIPA turn wireless hardware port off
/usr/sbin/networksetup -setairportpower $whwport off# turn wireless hardware port on
/usr/sbin/networksetup -setairportpower $whwport on
fi
fi
# Get the wireless network (wirelessnw)
wirelessnw=`networksetup -getairportnetwork $hwports | cut -d " " -f 4`
# Block wireless networkscase $wirelessnw in
$Block1)
networksetup -setairportpower $whwport off
;;
esac
# If logged in user is in I.S allow access to SSIDs but block everyone else!if
dscl . -read /Users/"${consoleuser}" | grep "$Dept"then echo "$Dept Allowed!"else# Block the restricted wireless networks with a case statement belowcase $wirelessnw in
$Block2|$Block3|$Block4)
# Turn off wifi
networksetup -setairportpower $whwport off# Set the preferred wireless network to WorkSSID
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex $whwport $WorkSSID $Index $AuthE
# Remove Wireless networks
/usr/sbin/networksetup -removeallpreferredwirelessnetworks $whwport
;;
esac
fi
# 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 wirelessif [ "$checkjss" == "The JSS is available." ]; then
/usr/sbin/jamf log
fi
exit 0
Thanks Jared i just got round to adding in your variables and this is what i am using now :)
#!/bin/bash################################################################################################################################################## HISTORY## Version: 2.8## - Created by Tim Kimpton on November 29th, 2012# - Assisted by Jared Nichols and Mike from JAMFNATION to clean up and simplify the blocked ssid case statement and network interface variables## Stops network bridging turning the relevant network interface off and on################################################################################################################################################## SETTING THE ENVIRONMENT VARIABLES# Get the ethernet hardware port (ehwport)
ehwport=`networksetup -listallhardwareports | awk '/.Ethernet/,/Ethernet Address/' | awk 'NR==2' | cut -d " " -f 2`
# 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 ' '`
# Current Logged in User
consoleuser=`ls -l /dev/console | cut -d " " -f4`
# Carry out an OS version check
OS=`/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'`
# Work SSID
WorkSSID=XXX
# Authentication to use eg WPA2 Enterprise
Auth=WPA2E
# Index for SSID
Index=0# Check to see if the JSS is available and if yes, then submits the current IP
checkjss=`/usr/sbin/jamf checkJSSConnection -retry 0 | grep "The JSS is available"`
# Department allowed to bypass SSID restrictions
Dept=XXX
# SSIDs to Block
Block1=XXX
Block2=XXX
Block3=XXX
Block4=XXX
##################################################################################### See if ethernet if active and if it is then we need to turn OFF the wirelesss interface!if ifconfig "${ehwport}" | grep inet; then
/usr/sbin/networksetup -setairportpower $whwport off# There is also a bug where wireless network interfaces are caching DNS and causes problems when switching networks, so we need to clear them!
/usr/sbin/networksetup -setdnsservers $wservice "empty"# if Ethernet is not active then...
elif ifconfig "${ehwport}" | grep inactive; then# Clear the DNS cache for the wireless network service
/usr/sbin/networksetup -setdnsservers $wservice "empty"# Do not ask to join new networks
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs joinmode=automatic joinmodefallback=donothing
# 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
fi
# Prevent 169 IP Address problem for Work SSIDif [ $SSID = $WorkSSID ]; thenif ifconfig "${whwport}" | grep 169;
then# If APIPA turn wireless hardware port off
/usr/sbin/networksetup -setairportpower $whwport off# turn wireless hardware port on
/usr/sbin/networksetup -setairportpower $whwport on
fi
fi
# Get the wireless network (wirelessnw)
wirelessnw=`networksetup -getairportnetwork $hwports | cut -d " " -f 4`
# Block wireless networkscase $wirelessnw in
$Block1)
networksetup -setairportpower $whwport off
;;
esac
# If logged in user is in I.S allow access to SSIDs but block everyone else!if
dscl . -read /Users/"${consoleuser}" | grep "$Dept"then echo "$Dept Allowed!"else# Block the restricted wireless networks with a case statement belowcase $wirelessnw in
$Block2|$Block3|$Block4)
# Turn off wifi
networksetup -setairportpower $whwport off# Set the preferred wireless network to WorkSSID
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex $whwport $WorkSSID $Index $AuthE
# Remove Wireless networks
/usr/sbin/networksetup -removeallpreferredwirelessnetworks $whwport
;;
esac
fi
# 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 wirelessif [ "$checkjss" == "The JSS is available." ]; then
/usr/sbin/jamf log
fi
exit 0
How do I deploy this in my network? I want to push this out on Casper, we have MANY staff members going to the Guest network instead of the "Staff" network. HELP!
@technicholas I used Lingon get this version it's free quick before its gone
http://sourceforge.net/projects/lingon/files/
I used Lingon to create a launch daemon (these run as root) to run the script. I included a watch path if a system file changed I think it was in /Library/Preferences/SystemConfiguration/xxx
I will have a look in the morning.
Anyway you will need to package them up and deploy, but TEST
That one is going to be tough as networksetup doesn't have an option for it. However, I found where the setting lives in the preference file if you're game to change it with a script. In /Library/Preferences/SystemConfiguration/preferences.plist you'll find a block like this:
There's a number of ways to churn through the file with a script to change it, and if you're at the proper level of skill to do it (as mucking with this file directly is probably bad mojo if you don't know what you're doing) I'll leave you to it. Otherwise you may want to consider it a "nice to have."
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.