Last active
March 29, 2023 19:42
-
-
Save talkingmoose/7d1bf4f884ca08f95fd3baf0014fc639 to your computer and use it in GitHub Desktop.
Add the following script to a Jamf Pro extension attribute to collect service provider location information based on public IP address when updating inventory.
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
#!/bin/zsh | |
# provide for Big Sur and earlier | |
xpath() { | |
# the xpath tool changes in Big Sur | |
if [[ $( /usr/bin/sw_vers -buildVersion) > "20A" ]]; then | |
/usr/bin/xpath -e "$@" | |
else | |
/usr/bin/xpath "$@" | |
fi | |
} | |
# get public IP address | |
publicIP=$( /usr/bin/curl http://ifconfig.me/ip \ | |
--location \ | |
--silent \ | |
--max-time 10 ) | |
# get GeoIP data | |
locationData=$( /usr/bin/curl http://ip-api.com/xml/$publicIP \ | |
--location \ | |
--silent \ | |
--max-time 10 ) | |
locationPieces=( country countryCode region regionName city zip lat lon timezone isp org as ) | |
for anItem in $locationPieces | |
do | |
export $anItem="$( xpath "/query/$anItem/text()" 2>/dev/null <<< "$locationData" )" | |
done | |
echo "<result>$country | |
$countryCode | |
$region | |
$regionName | |
$city | |
$zip | |
$lat | |
$lon | |
$timezone | |
$isp | |
$org | |
$as</result>" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@remusache, I was recently made aware of an xpath change in Big Sur. The script will need to be tweaked a little. See this for information about what to do.
https://scriptingosx.com/2020/10/dealing-with-xpath-changes-in-big-sur/
I won't be able to test and confirm this change for a little while.