Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created April 9, 2024 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talkingmoose/d7286deacfd7c8206d1f7f79a361ff78 to your computer and use it in GitHub Desktop.
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.
#!/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