Skip to main content
Question

Wifi Network Priority Script


Forum|alt.badge.img+18
  • Esteemed Contributor
  • 831 replies

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

6 replies

Forum|alt.badge.img+10
  • Contributor
  • 88 replies
  • January 20, 2022

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


chrisdaggett
Forum|alt.badge.img+7
  • Valued Contributor
  • 94 replies
  • March 25, 2022

Same scenario. 


Forum|alt.badge.img+4
  • New Contributor
  • 3 replies
  • June 1, 2022

The same scenario also.


Forum|alt.badge.img+5
  • Contributor
  • 26 replies
  • June 14, 2022

Looking for a solution to this as well.


MrChris
Forum|alt.badge.img+3
  • New Contributor
  • 10 replies
  • December 5, 2022

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?


Forum|alt.badge.img+18
  • Author
  • Esteemed Contributor
  • 831 replies
  • December 6, 2022
MrChris wrote:

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?


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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings