Posted on 02-16-2015 12:45 PM
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.
Solved! Go to Solution.
Posted on 02-16-2015 12:51 PM
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
Posted on 02-16-2015 12:51 PM
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
Posted on 02-16-2015 12:53 PM
Thank you, I will try out.
Posted on 02-16-2015 01:25 PM
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
Posted on 02-16-2015 01:41 PM
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