Home > Jamf Pro, Mac administration, Scripting > Detecting via Jamf Pro if a Mac is being issued an IPv4 or IPv6 address
I assisted a colleague recently with an interesting request – how to detect if a Mac is only being issued an IPv6 address? In this instance, the use case was for when a Mac is on a network where only IPv6 addresses are being issued by DHCP (so no IPv4 addresses are available.)
The idea was to get a Yes or No answer for whether any of the Mac’s network interfaces were being issued an IPv4 address, where Yes meant that at least one network interface had an IPv4 IP address and No if none of the network interfaces had an IPv4 IP address.
After some research and discussion with colleagues in the Mac Admins Slack, this information was available via the system_profiler command line tool, using the SPNetworkDataType datatype. You can parse the output from the system_profiler tool using the following command to get a count of how many IPv4 addresses are in use by the various network interfaces on a Mac:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For example, if your Mac has IPv4 IP addresses assigned to both Ethernet and Wi-Fi, you should see output like this to show that your Mac has two assigned IPv4 addresses (one for Ethernet and one for Wi-Fi):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This same approach works for IPv6 addresses, where you can parse the output from system_profiler using the following command to get a count of how many IPv6 addresses are in use by the various network interfaces on a Mac:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For example, if your Mac has no IPv6 IP addresses assigned to any network interfaces, you should see output like this to show that your Mac has no assigned IPv6 addresses:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I’ve used this technique to create Jamf Pro Extension Attributes which can help figure out if a particular Mac has IPv4 or IPv6 addresses assigned to it, which can help in the use case I discussed earlier to help figure out if no IPv4 or no IPv6 addresses are available to a particular Mac. For more details, please see below the jump.
I’ve written two Extension Attributes, one for detecting IPv4 addresses and the other for IPv6 addresses. Here’s how they work:
Detects if an IPv4 / IPv6 network address is being used on a Mac. It returns the value below if one or more IPv4 / IPv6 addresses are detected on the Mac’s various network interfaces.
1
In all other cases, the value below is returned:
0
The Extension Attribute’s returned value ( 1 or 0 ) can then be used as Jamf Pro smart group criteria.
IPv4 version of the Extension Attribute:
IPv6 version of the extension attribute: