Reporting Mac location in JSS

hsert
New Contributor II

Hello,
I was working on a project to implement the location tracking on all our managed devices. I tried many solutions but at the end I fund something similar to the Google API called Here. (Previously owned by Nokia). I don't know if this solution is less accurate in the devices location but you can make 250'000 API queries with the Freemium plan.

You can find bellow the script I'm using to set an Extension attribute (can also be used in a policy) :

PS : replace the apiKey="XXXXXXXXXXXXXXX" with your apiKey (Create your developer account : https://developer.here.com/)

#!/bin/sh

ASSETSERIALNUMBER=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
INTERFACE=$(networksetup -listallhardwareports | grep -A1 Wi-Fi | tail -1 | awk '{print $2}')
STATUS=$(networksetup -getairportpower $INTERFACE | awk '{print $4}')
if [ $STATUS = "Off" ] ; then
    networksetup -setairportpower $INTERFACE on
    sleep 10
    TURNOFFAGAIN="True"
fi

network=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s | tail -n +2 | awk '{print substr($0, 34, 17)"$"substr($0, 52, 4)"$"substr($0, 1, 32)}' | sort -t $ -k2,2rn | head -12)

echo "$network" >> /tmp/gl_ssids.txt

OLD_IFS=$IFS
IFS="$"
URL="{"wlan": ["
exec 5</tmp/gl_ssids.txt
while read -u 5 MAC SS SSID
do
    MAC=`echo $MAC | sed "s/^ *//g" | sed "s/ *$//g"`
    URL+="{"mac": "$MAC"},"
done
IFS=$OLD_IFS

 URL=$( echo $URL | rev | cut -c2- | rev)
 URL+="]}"

apiKey="XXXXXXXXXXXXXXX"
GetLocation=$(curl -H "Content-Type: application/json" -H "Accept: application/json" -d "$URL" -X POST  "https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=${apiKey}")  

if [[  $GetLocation == *"code"* ]]; then
        echo "<result>Last location not fund</result>"
else

    format=$( echo "$GetLocation" | tr -d "," | tr -d "{"location":{"lat":" )
    LAT=$(echo "$format" | sed 's/g.*//')

    LONG=$(echo "$format"  | sed -e 's///g/g' | awk -F "g" '{print $2}')
    LONG=$(echo "$LONG" | sed 's/u.*//')

    echo "<result>LAT : $LAT LONG : $LONG</result>"
fi

if [ "$TURNOFFAGAIN" == "True" ] ; then
    networksetup -setairportpower $INTERFACE off
fi

rm /tmp/gl_ssids.txt
3 REPLIES 3

Girishbc1
New Contributor

Can you please let me know how to find API key ?

Thank you i have generated API key, will test the same