Creating a Script to check for specific SSID availability and connect if available.

Anonymous
Not applicable

What I'm looking for is a script to run online/offline to check to see if a specific SSID (on site wifi) is available and if so to connect to that wifi.
Or if it has to be connect to a specific SSID if that not available connect to preferred networks...

I'm looking for a way to get computers connected to our network if they lose network connection without the users having to do anything but maybe log out and log back in.

7 REPLIES 7

BOBW
Contributor II

Can you use a profile with WIFI payload through JAMF Pro?

Anonymous
Not applicable

We are looking for a backup in case the wifi payload is removed.

jtrant
Valued Contributor

Make the configuration profile non-removable? Once the Jamf MDM profile is present, the WiFi profile will be too.

Anonymous
Not applicable

I have computers with a configuration profile to connect to a SSID and to auto join that network. I make a change to that configuration profile and turn off auto join. Most computers are on a different SSID so it shouldn't affect them But the ones that are on this SSID, lose their internet connection when the profile is removed to. be added back with the auto join turned off.

So I want a way to be able to run a script that checks for network access.. if no network access and specific SSID is available to connect to that SSID.

BOBW
Contributor II

How is this? fill out your SSID you require connection to, your secondary network SSID and secondary wifi Password. NOTE: this will send your PW in clear text of course but if this does not worry you, this should work.
You could even add a LaunchAgent with a StartInterval of a determined time and it should be pretty automatic.

#!/bin/bash requiredssid= secondarywifi= secondarywifiPW= wifiport=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}') currentssid=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork | awk '{print $4}' ) echo $currentssid echo $wifiport if [ "$currentssid" != "$requiredssid" ] then echo incorrect networksetup -setairportnetwork $wifiport $secondarywifi $secondarywifiPW else echo "wifi correct, no action required" fi sudo jamf log

BOBW
Contributor II

This one might work better though..... I actually read your requirements

#!/bin/bash


#checks to see your current SSID does not match your required SSID - if success exit
# If it is not then will attempt to connect to primary SSID 
#IF this cannot happen or the network is not available then it will attempt to connect to secondary

requiredssid=
primaryssidpw=
secondarywifi=
secondarywifiPW=

wifiint=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}')
currentssid=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork | awk '{print $4}' )
wifiavailable=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s | grep "$requiredssid" )



echo "current SSID $currentssid"
echo "Required SSID $requiredssid"
echo "Current interface $wifiint"


if [ "$wifiavailable" != "" ]
    then
    echo "Wifi connected to $currentssid no change required"
exit 0

else

    echo "attempting to connect to primary SSID"

networksetup -setairportnetwork "$wifiint" "$requiredssid" "$primaryssidpw"
    sleep 10

        if [ "$currentssid" != "$requiredssid" ]
        then 
            echo "Primary SSID not available Attempting Secondary $secondarywifi"

        networksetup -setairportnetwork "$wifiint" "$secondarywifi" "$secondarywifiPW"

        fi

fi

currentssid=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork | awk '{print $4}' )
        if [ "$currentssid" != "$requiredssid" ]
        then 
            echo "Sorry, we are unable to connect to wifi"
        else
            echo "Wifi connected to $currentssid"

        fi


sudo jamf log

exit 0

Anonymous
Not applicable

Thank you! I will test that.