Posted on 03-07-2017 02:31 PM
I saw an Extension Attribute "Current AirPort Network". How can I use this to list clients connected to a specific SSID. We have a School that we want to move all clients to the new SSID because the password was compromised (we are working on RADIUS authentication but not finished yet as we want to integrate it with the Lightspeed Rocket content filter) I pushed a script to connect them to the new SSID, and remove the old SSID from Preferred Network List. I scoped by Network Segment, once per computer. What I would like to do is, create a smartgroup with clients connected to the old ssid, and use it as my Scope. Run the policy ongoing until all of them is no longer with that smartgroup. I scheduled to deactivate the policy after 1 week and extend it if necessary.
Solved! Go to Solution.
Posted on 03-08-2017 02:59 AM
Need to output the result like this in the extension attrib
#!/bin/sh
value=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}')
echo "<result>$value</result>"
Posted on 03-08-2017 04:05 AM
The script i use
#!/bin/sh
result=`/usr/sbin/networksetup -getairportnetwork en0 | awk '{ print $4 }'`
echo "<result>$result</result>"
Posted on 03-07-2017 02:38 PM
I see this too when pulling the computer properties.
Posted on 03-07-2017 04:18 PM
This command will get you the current SSID. You can turn it into an extension attribute that you can then make a smart group from.
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | sed -n 13p | awk '{print $2}'
Posted on 03-07-2017 05:38 PM
@iJake Thank's Sir, I will try this right now.
Posted on 03-08-2017 01:05 AM
Maybe there is something I am doing wrong. When I run it manually, it prints out the SSID. But it doesn't work as an Extension Attribute.
Also, the command you posted seems to be not printing SSID with spaces. So I modified it with this.
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'
But still no go when I convert it to Extension Attribute.
Posted on 03-08-2017 02:59 AM
Need to output the result like this in the extension attrib
#!/bin/sh
value=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}')
echo "<result>$value</result>"
Posted on 03-08-2017 04:05 AM
The script i use
#!/bin/sh
result=`/usr/sbin/networksetup -getairportnetwork en0 | awk '{ print $4 }'`
echo "<result>$result</result>"
Posted on 03-08-2017 05:30 AM
@iJake Your command doesn't account for SSIDs that have spaces in the name. I only get the first word from an SSID that is comprised of 3 words. The one I use is similar, but looks like this:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | sed 's/^ *//g' | awk -F': ' '/^SSID/{print $NF}'
That will output the full SSID name, including any spaces.
Posted on 03-08-2017 07:52 AM
@mm2270 This is what I get for posting at the end of the work day. :) Thanks!
Posted on 06-19-2019 08:55 AM
While others have already solved this problem, I'm biased in favor of code that's easy to understand.
So I wrote it using cut, which cuts a string of text from a larger string. (SED and AWK are great tools, but they aren't easy to understand.)
As has already been discussed, this:/usr/sbin/networksetup -getairportnetwork en0
returns the SSID name in this format:Current Wi-Fi Network: Starbucks WiFi
If you count, you'll see that the SSID name begins at the 24th character. We can't know where it ends, but since an SSID can't be more than 32 characters, then the SSID will always end at or before the 56th character.
So we need to cut from character 32 to character 56, and this is how we do it: `/usr/sbin/networksetup -getairportnetwork en0` | cut -c 24-56
(The -c option means to cut characters; -b is used to cut bytes; see man cut
for more options.)
Here it is as an extension attribute based on the above:
#!/bin/sh
# Jamf Extension attribute to return SSID
result=`/usr/sbin/networksetup -getairportnetwork en0 | cut -c 24-56`
echo "<result>$result</result>"
exit 0
Posted on 06-19-2019 12:35 PM
My above extension attribute script works, but if en0 is anything other than Wi-Fi, the result is this awkward string: "rface. ng wireless information."
So I added an if/then to check for this condition, and report "No Wi-Fi" if no SSID exists.
New script follows.
#!/bin/sh
# Jamf Extension attribute to return SSID
#
# Check for SSID name
wifi_name=`/usr/sbin/networksetup -getairportnetwork en0`
#
# If an SSID name is found, save it in result. Otherwise, set result to "No Wi-Fi"
if [[ $wifi_name != "en0 is not a Wi-Fi interface"* ]];
then
result=$( echo "$wifi_name" | cut -c 24-56)
else
result="No Wi-Fi"
fi
#
# Result for Jamf
echo "<result>$result</result>"
exit 0
Posted on 06-19-2019 12:43 PM
Nevermind
Posted on 05-18-2021 08:58 PM
We pulled an EA from Jamf's webpage Created by Justin Sako on February 11, 2015. Has been working great until Big Sur came along. We're now getting the error, "The networksetup binary is not present on this machine."
Has anyone updated the script to add Big Sur support?