Has Wi/Fi Extension Attributes

lpadmin
Contributor

Hello, I am trying to create a Extension Attribute to show me which computers have a network called LP-Admin in their preferred network list. I found this script which will show all of their networks on a Macbook Air

networksetup -listpreferredwirelessnetworks en0

Not sure if that will be helpful for the script or not. I am completely new to scripting any help will be much appreciated.

1 ACCEPTED SOLUTION

jesseshipley
Contributor

It is pretty simple. You do an if statement where it looks to see if LP-Admin is in the resulting text of the command you mentioned. Extension attributes always look for whatever is between <result> and </result> so you echo the response for when it is true and for when it isn't. Hope this helps.

#!/bin/sh
if $(networksetup -listpreferredwirelessnetworks en0 | grep -q "LP-Admin"); then
    echo '<result>TRUE</result>'
else
    echo '<result>FALSE</result>'
fi

View solution in original post

4 REPLIES 4

jesseshipley
Contributor

It is pretty simple. You do an if statement where it looks to see if LP-Admin is in the resulting text of the command you mentioned. Extension attributes always look for whatever is between <result> and </result> so you echo the response for when it is true and for when it isn't. Hope this helps.

#!/bin/sh
if $(networksetup -listpreferredwirelessnetworks en0 | grep -q "LP-Admin"); then
    echo '<result>TRUE</result>'
else
    echo '<result>FALSE</result>'
fi

lpadmin
Contributor

Thank you, I will try out.

Chris
Valued Contributor

Just to add, on Macs with an internal NIC the WiFi interface is usually en1.
You can use

networksetup -listallhardwareports | egrep -A 2 "(AirPort|Wi-Fi)" | grep Device | awk '{print $2}'

to get the WiFi interface dynamically

jesseshipley
Contributor

Good catch @Chris. @lpadmin you should use this script instead if you have any Macs with built in ethernet.

#!/bin/sh
#get wifi interface
interface= $(networksetup -listallhardwareports | egrep -A 2 "(AirPort|Wi-Fi)" | grep Device | awk '{print $2}')

#check for LA-Admin network
if $(networksetup -listpreferredwirelessnetworks $interface | grep -q "LP-Admin"); then
    echo '<result>TRUE</result>'
else
    echo '<result>FALSE</result>'
fi