Skip to content

Instantly share code, notes, and snippets.

@benbeton benbeton/beacon_scan.sh Secret
Created Jan 16, 2016

Embed
What would you like to do?
beacon scan sample script
#!/bin/bash
# iBeacon Scan by Radius Networks
if [[ $1 == "parse" ]]; then
packet=""
capturing=""
count=0
while read line
do
count=$[count + 1]
if [ "$capturing" ]; then
if [[ $line =~ ^[0-9a-fA-F]{2}\ [0-9a-fA-F] ]]; then
packet="$packet $line"
else
if [[ $packet =~ ^04\ 3E\ 2A\ 02\ 01\ .{26}\ 02\ 01\ .{14}\ 02\ 15 ]]; then
UUID=`echo $packet | sed 's/^.\{69\}\(.\{47\}\).*$/\1/'`
MAJOR=`echo $packet | sed 's/^.\{117\}\(.\{5\}\).*$/\1/'`
MINOR=`echo $packet | sed 's/^.\{123\}\(.\{5\}\).*$/\1/'`
POWER=`echo $packet | sed 's/^.\{129\}\(.\{2\}\).*$/\1/'`
UUID=`echo $UUID | sed -e 's/\ //g' -e 's/^\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)$/\1-\2-\3-\4-\5/'`
MAJOR=`echo $MAJOR | sed 's/\ //g'`
MINOR=`echo $MINOR | sed 's/\ //g'`
POWER=$[POWER - 256]
if [[ $2 == "-b" ]]; then
#echo "$UUID $MAJOR $MINOR $POWER"
echo "$UUID"
else
echo "UUID: $UUID MAJOR: $MAJOR MINOR: $MINOR POWER: $POWER"
fi
fi
capturing=""
packet=""
fi
fi
if [ ! "$capturing" ]; then
if [[ $line =~ ^\> ]]; then
packet=`echo $line | sed 's/^>.\(.*$\)/\1/'`
capturing=1
fi
fi
done
else
sudo hcitool lescan --duplicates 1>/dev/null &
if [ "$(pidof hcitool)" ]; then
sudo hcidump --raw | ./$0 parse $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.