Skip to main content

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.

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

Thank you, I will try out.


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


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