Wifi Network Priority Script

GabeShack
Valued Contributor III

Anyone still using a script to manage order of preferred wireless networks in MacOS 11 or above?  If so is it working?

We were using the script from Paul Nelson, but since Apple separated the /Library/Preferences/\
SystemConfiguration/com.apple.airport.preferences.plist and put the known-networks in a separate file in 

/Library/Preferences/com.apple.wifi.known-networks.plist

it seems like all the old scripts to do this are broken

Gabe Shackney
Princeton Public Schools
6 REPLIES 6

AtillaTheC
Contributor II

I'm also looking for a replacement to the python script since its being depreciated in Monterey. 

chrisdaggett
Contributor II

Same scenario. 

ldelancy
New Contributor II

The same scenario also.

btowns
New Contributor III

Looking for a solution to this as well.

MrChris
New Contributor III

Bumping this one. Anybody made any progress on this or identified a viable solution/alternative to the original script referenced for Wifi/SSID network priority?

GabeShack
Valued Contributor III

Well I ended up going in a different direction on this.  Since we have one network that we want all staff and students to join, and another for guests, I now run a script that looks if they are on the guest IP address and then adds them to a static group that then removes the main network profile, then it removes them from the static group and the network profile then gets re added, which then pushes the main network back to the top I believe.

Its been awhile since I started doing this, but it seems to work really well.  So I exclude this static group from the main network profile and its made just for specifically district devices that are on the guest network by mistake.

SO this is scoped to all staff and student devices, but limited to only those with an ip associated with our guest network.  Since network changes are reported pretty instantly, this should run immediately once they show up with that IP.

 

#!/bin/bash
jamfproURL="https://YourJamfServerHere"
groupid="StaticGroupIDnumberHERE"
current_user=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')
action="additions"
APIUser="$6"
APIPass="$7"
ComputerSerial=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')

xml="<computer_group><computer_${action}><computer><serial_number>$ComputerSerial</serial_number></computer></computer_${action}></computer_group>"

fullURL="${jamfproURL}/JSSResource/computergroups/id/${groupid}"

echo "Created XML"
echo $xml

echo "Jamf API URL"
echo $fullURL


result=$`curl "$fullURL" -u "$APIUser:$APIPass" -H "Content-Type: text/xml" -X PUT -d "$xml"`

echo "result"
echo "$result"

    if [[ "$result" == *"<p>The request requires user authentication</p>"* ]] ; then
        echo "Add Failed"
    else
        echo "Add to Static Group probably successful."     
fi
exit 0

 

Then once added to the group, the profile is removed so 2nd script runs to remove it from the same static group:

 

#!/bin/bash
jamfproURL="YourServerAddressHere"
groupid="YourStaticGroupIDHERE"
current_user=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')
action="deletions"
APIUser="$6"
APIPass="$7"
ComputerSerial=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')

xml="<computer_group><computer_${action}><computer><serial_number>$ComputerSerial</serial_number></computer></computer_${action}></computer_group>"

fullURL="${jamfproURL}/JSSResource/computergroups/id/${groupid}"

echo "Created XML"
echo $xml

echo "Jamf API URL"
echo $fullURL


result=$`curl "$fullURL" -u "$APIUser:$APIPass" -H "Content-Type: text/xml" -X PUT -d "$xml"`

echo "result"
echo "$result"

    if [[ "$result" == *"<p>The request requires user authentication</p>"* ]] ; then
        echo "Add Failed"
    else
        echo "Remove from Static Group probably successful."     
fi
exit 0

 

Then I tell it to remove the guest network from the list of preferred networks so it wont rejoin:

 

#!/bin/sh

##Get the wireless port ID
WirelessPort=$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')

##Run a SSID removal if its present
networksetup -removepreferredwirelessnetwork $WirelessPort "Princeton Schools Guest" 2>/dev/null

exit 0

 

So not sure if this helps at all but maybe this is something others can use.

Gabe Shackney
Princeton Public Schools