Skip to main content

I need to pull a report of all MAC addresses for the computers in my environment and the built-in reporting only can display the Primary MAC address. From other posts it seems the only way is with Extension Attributes but the few scripts I've found (https://community.jamf.com/t5/jamf-pro/how-to-customize-what-gets-inventory-for-primary-mac-address-and/m-p/193541#M182332) don't return any results when creating extension attributes. Does anyone have any ideas on how I can grab this info?

Thanks!

The really bare bones result:


#!/bin/bash

result=$(/usr/sbin/networksetup -listallhardwareports | awk '/Address:/ { print $NF }')
echo "<result>$result</result>"

Note that this approach doesn't consider whether an interface is active (connected) or not; consider your use case for gathering this info. Could probably also be improved with a `printf` instead but this was off the top of my head.


The really bare bones result:


#!/bin/bash

result=$(/usr/sbin/networksetup -listallhardwareports | awk '/Address:/ { print $NF }')
echo "<result>$result</result>"

Note that this approach doesn't consider whether an interface is active (connected) or not; consider your use case for gathering this info. Could probably also be improved with a `printf` instead but this was off the top of my head.


Thanks for this! However, I see it populates with what looks like 7 MAC addresses instead of the 2 I was expecting. I don't suppose there's a way to filter to just the 2 Network adapters? It looks like the 1st and 4th MAC addresses are what I need...


Thanks for this! However, I see it populates with what looks like 7 MAC addresses instead of the 2 I was expecting. I don't suppose there's a way to filter to just the 2 Network adapters? It looks like the 1st and 4th MAC addresses are what I need...


Assuming you're only considering en0 and en1, you could simply run:


networksetup -getmacaddress en0
networksetup -getmacaddress en1

Maybe clean up the output a bit with:


networksetup -getmacaddress en0 | awk '/Address:/ { print $5 " " $3 " " }' | tr -d '()'

Assuming you're only considering en0 and en1, you could simply run:


networksetup -getmacaddress en0
networksetup -getmacaddress en1

Maybe clean up the output a bit with:


networksetup -getmacaddress en0 | awk '/Address:/ { print $5 " " $3 " " }' | tr -d '()'

Correct, those are the only considerations. Unfortunately none of those commands are returning any results when made into extension attributes. Is there something else I should be inputting along with your commands to make them work?


Correct, those are the only considerations. Unfortunately none of those commands are returning any results when made into extension attributes. Is there something else I should be inputting along with your commands to make them work?


For any EA to report a value back to the JSS, the output has to be enclosed in "<result></result>" tags.


So:


#!/bin/bash

result=$(/usr/sbin/networksetup -getmacaddress en0 | awk '/Address:/ { print $5 " " $3 " " }' | tr -d '()')

printf "<result>$result</result>"

The shebang says this is a bash script.


'result' defines the value of the newly declared variable with the results of the commands contained within $().


'printf' is often better for multi-line output, but an 'echo' is more typical. '$result' means display the value of that variable.


If you're just starting with EAs, check out Jamf's training entries.


This is exactly what I needed, thank you so much! I added your script to 1 EA then copied and changed to en1 with another and now both MAC addresses are displayed. I am in fact just getting started with EAs (in case it wasn't painfully obvious) so I will definitely check out the training on them. Thanks again and have a great rest of your day!


Reply