Detecting via Jamf Pro if a Mac is being issued an IPv4 or IPv6 address
2024-10-10 23:12:2 Author: derflounder.wordpress.com(查看原文) 阅读量:17 收藏

Home > Jamf Pro, Mac administration, Scripting > Detecting via Jamf Pro if a Mac is being issued an IPv4 or IPv6 address

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:


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 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:


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:


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:

https://github.com/rtrouton/rtrouton_scripts/tree/main/rtrouton_scripts/Casper_Extension_Attributes/check_for_IPv4_address_used_on_Mac

IPv4 Jamf Pro Extension Attribute Setup.

IPv6 version of the extension attribute:

https://github.com/rtrouton/rtrouton_scripts/tree/main/rtrouton_scripts/Casper_Extension_Attributes/check_for_IPv6_address_used_on_Mac

IPv6 Jamf Pro Extension Attribute Setup.


文章来源: https://derflounder.wordpress.com/2024/10/10/detecting-via-jamf-pro-if-a-mac-is-being-issued-an-ipv4-or-ipv6-address/
如有侵权请联系:admin#unsafe.sh