Monday
Trying to find a simple solution to give me the IP address of an ethernet connection to a mac, if its through a USB-C adapter or a docking station.
Most of the macs stay connected to our wifi, and the service order usually puts that first so the built in jamf reporting is always giving us the wifi IP. I would like to create an EA to give me ethernet... (even if there isnt one and the computer is only on wifi thats fine, it can report "none" or nothing.)
Monday
@matherton I don't have the spare cycles to generate a fully functional EA but following should report any active wired ethernet connection a Mac:
ifconfig | grep -B 7 -w active | grep -B 6 duplex
You'll need to parse the output of that to extract the IPv4 or IPv6 address, and note that there's nothing that says you can't have multiple active wired interfaces.
Monday
#!/bin/bash
ethernet_ip=$(ifconfig | awk '/active/{iface=$1} iface && /inet / {print $2; exit}')
echo "<result>$ethernet_ip</result>"
Monday
@A_Collins That'll get you the active IPv4 address but not restrict it to one that's for a wired connection.
Tuesday
Depending on what you are needing, MDM is not fast enough.
The MAC address you see in Jamf is for the primary network service which is usually wifi on devices. The secondary MAC address is usually a tunnel of some sort. Jamf wont know what the the data for an EA until the device checks in, if you are using this to feed data to a Network Security tool this wont be fast enough to prevent action.
Tuesday
nope not urgency needed, just want to see the reported connections in case we need to fix things or figure out locations.
Tuesday
I'd started something similar to this a few months ago, never completed it. Here's a script that'll grab all active ports and you can edit it or make an EA as needed. It may still need some work.
#!/bin/sh
# Active ports.sh
# Created by Ed C on 12/13/24.
# Display active network services and IP Addresses
networkServices=$( /usr/sbin/networksetup -listallnetworkservices | /usr/bin/grep -v asterisk )
activeServices=""
while IFS= read -r aService
do
activePort=$( /usr/sbin/networksetup -getinfo "$aService" | /usr/bin/grep "IP address" | /usr/bin/grep -v "IPv6" )
if [ -n "$activePort" ]; then
activeServices="${activeServices}\n${aService} ${activePort}"
fi
done <<< "$networkServices"
activeServices=$( echo "$activeServices" | /usr/bin/sed '/^$/d')
echo "$activeServices"