iCloud Find My Mac through Casper.

michelm
New Contributor

Hi Guys,

We are a school and we have around 500 Macs that we would like to be able to track them offsite.
Anyone found a way to set up iCloud Find My Mac through Casper?

Regards,
MM

1 ACCEPTED SOLUTION

HangerS
New Contributor II

Not exactly what you are asking for but we are using something like this when computers get stolen. Not my script (think it was found here).

#!/bin/sh
INTERFACE=$(networksetup -listallhardwareports | grep -A1 Wi-Fi | tail -1 | awk '{print $2}')
STATUS=$(networksetup -getairportpower $INTERFACE | awk '{print $4}')
if [ $STATUS = "Off" ] ; then
    sleep 5
    networksetup -setairportpower $INTERFACE on
fi

/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 > /tmp/gl_ssids.txt

if [ $STATUS = "Off" ] ; then
    networksetup -setairportpower $INTERFACE off
fi

OLD_IFS=$IFS
IFS="$"
URL="https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=false"
exec 5</tmp/gl_ssids.txt
while read -u 5 MAC SS SSID
do
    SSID=`echo $SSID | sed "s/^ *//g" | sed "s/ *$//g" | sed "s/ /%20/g"`
    MAC=`echo $MAC | sed "s/^ *//g" | sed "s/ *$//g"`
    SS=`echo $SS | sed "s/^ *//g" | sed "s/ *$//g"`
    URL+="&wifi=mac:$MAC&ssid:$SSID&ss:$SS"
done
IFS=$OLD_IFS

#echo $URL
curl -s -A "Mozilla" "$URL" > /tmp/gl_coordinates.txt
LAT=`cat /tmp/gl_coordinates.txt | grep "lat" | awk '{print $3}' | tr -d ","`
LONG=`cat /tmp/gl_coordinates.txt | grep "lng" | awk '{print $3}' | tr -d ","`
ACC=`cat /tmp/gl_coordinates.txt | grep "accuracy" | awk '{print $3}' | tr -d ","`
#echo "LAT:  $LAT"
#echo "LONG: $LONG"
#echo "ACC: $ACC"

curl -s -A "Mozilla" "http://maps.googleapis.com/maps/api/geocode/json?latlng=$LAT,$LONG&sensor=false" > /tmp/gl_address.txt
ADDRESS=`cat /tmp/gl_address.txt | grep "formatted_address" | head -1 | awk '{$1=$2=""; print $0}' | sed "s/,$//g" | tr -d " | sed "s/^ *//g"`

#if [ $EA -ne 0 ] ; then
#    echo "<result>$ADDRESS (lat=$LAT, long=$LONG, acc=$ACC)</result>"
#else
    echo "$ADDRESS (lat=$LAT, long=$LONG, acc=$ACC)"
#fi

rm /tmp/gl_ssids.txt /tmp/gl_coordinates.txt /tmp/gl_address.txt

View solution in original post

7 REPLIES 7

HangerS
New Contributor II

Not exactly what you are asking for but we are using something like this when computers get stolen. Not my script (think it was found here).

#!/bin/sh
INTERFACE=$(networksetup -listallhardwareports | grep -A1 Wi-Fi | tail -1 | awk '{print $2}')
STATUS=$(networksetup -getairportpower $INTERFACE | awk '{print $4}')
if [ $STATUS = "Off" ] ; then
    sleep 5
    networksetup -setairportpower $INTERFACE on
fi

/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 > /tmp/gl_ssids.txt

if [ $STATUS = "Off" ] ; then
    networksetup -setairportpower $INTERFACE off
fi

OLD_IFS=$IFS
IFS="$"
URL="https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=false"
exec 5</tmp/gl_ssids.txt
while read -u 5 MAC SS SSID
do
    SSID=`echo $SSID | sed "s/^ *//g" | sed "s/ *$//g" | sed "s/ /%20/g"`
    MAC=`echo $MAC | sed "s/^ *//g" | sed "s/ *$//g"`
    SS=`echo $SS | sed "s/^ *//g" | sed "s/ *$//g"`
    URL+="&wifi=mac:$MAC&ssid:$SSID&ss:$SS"
done
IFS=$OLD_IFS

#echo $URL
curl -s -A "Mozilla" "$URL" > /tmp/gl_coordinates.txt
LAT=`cat /tmp/gl_coordinates.txt | grep "lat" | awk '{print $3}' | tr -d ","`
LONG=`cat /tmp/gl_coordinates.txt | grep "lng" | awk '{print $3}' | tr -d ","`
ACC=`cat /tmp/gl_coordinates.txt | grep "accuracy" | awk '{print $3}' | tr -d ","`
#echo "LAT:  $LAT"
#echo "LONG: $LONG"
#echo "ACC: $ACC"

curl -s -A "Mozilla" "http://maps.googleapis.com/maps/api/geocode/json?latlng=$LAT,$LONG&sensor=false" > /tmp/gl_address.txt
ADDRESS=`cat /tmp/gl_address.txt | grep "formatted_address" | head -1 | awk '{$1=$2=""; print $0}' | sed "s/,$//g" | tr -d " | sed "s/^ *//g"`

#if [ $EA -ne 0 ] ; then
#    echo "<result>$ADDRESS (lat=$LAT, long=$LONG, acc=$ACC)</result>"
#else
    echo "$ADDRESS (lat=$LAT, long=$LONG, acc=$ACC)"
#fi

rm /tmp/gl_ssids.txt /tmp/gl_coordinates.txt /tmp/gl_address.txt

View solution in original post

michelm
New Contributor

Can you clarify what does this actually do?
Do you deploy it to all Macs as a policy or how exactly do you use it?
Does it need to be tweaked for our own environment in any way?

RobertBasil
Contributor

We just deploy it as a script and then can look in the log for that Policy at any time to see a laptops last reported location.

PAC
Contributor

@HangerS Thanks for the script. really nice!
If we don't use Mozilla, can i just change it to something like Safari?

#echo $URL
curl -s -A "Safari" "$URL" > /tmp/gl_coordinates.txt

Cheers

jchurch
Contributor II

i have a question about this statment,

if [ $STATUS = "Off" ] ; then networksetup -setairportpower $INTERFACE off fi

if you wifi is off then turn it off anyway? am i not reading that correctly?

HangerS
New Contributor II

@peter.caldwell Not my script but you're welcome 😃
It should not matter if you use Mozilla or not it should work with original code anyway.

@michelm It basically connects to any open wifi access point or connect to anyone already configured and fetch coordinates from google and then post them in an echo so you will se where the computer is when policy has ben run. We are only using this in a "stolen" static group if we loose any computer. But you can ofcource run it on regular basis if you want to track your computers.

@jchurch if wifi was off from the beginning it disables it again when done. So we don't leave an obvious trace that we have tracked the computer.

Maxalot
New Contributor III

Tried it. Nice.