Posted on 04-04-2017 06:58 PM
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
Solved! Go to Solution.
Posted on 04-05-2017 01:49 AM
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
Posted on 04-05-2017 01:49 AM
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
Posted on 04-05-2017 03:12 PM
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?
Posted on 04-05-2017 04:43 PM
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.
Posted on 04-11-2017 03:57 PM
@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
Posted on 04-11-2017 05:20 PM
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?
Posted on 04-11-2017 11:24 PM
@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.
Posted on 05-13-2019 10:49 AM
Tried it. Nice.
Posted on 02-08-2022 08:12 AM
Is there an update to this script for Catalina/Big Sur/Monterey? I ran the script on a test computer with Bug Sur and I got some errors. It doesn't recognize the "tr" and "print" commands.