Created
April 9, 2024 16:50
-
-
Save talkingmoose/d7286deacfd7c8206d1f7f79a361ff78 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 | |
# 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="$( /usr/bin/xmllint --xpath "/query/$anItem/text()" <<< "$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