forked from andrewjfreyer/monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata
68 lines (57 loc) · 2.47 KB
/
data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# ----------------------------------------------------------------------------------------
# GENERAL INFORMATION
# ----------------------------------------------------------------------------------------
#
# Written by Andrew J Freyer
# GNU General Public License
# http://github.com/andrewjfreyer/monitor
#
# PACKET INFORMATION GATHERING
#
# ----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# OBTAIN MANUFACTURER INFORMATION FOR A PARTICULAR BLUETOOTH MAC ADDRESS
# ----------------------------------------------------------------------------------------
determine_manufacturer () {
#IF NO ADDRESS, RETURN BLANK
if [ -n "$1" ]; then
local address="$1"
#VERIFY THIS IS A MAC ADDRESS
[[ $address =~ ([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2} ]] && manufacturer="Unknown"
#SET THE FILE IF IT DOESN'T EXIST
[ ! -f ".manufacturer_cache" ] && echo "" > ".manufacturer_cache"
#CHECK CACHE
local manufacturer=$(grep "${address:0:8}" < ".manufacturer_cache" | awk -F "\t" '{print $2}' | sort -u | head -1)
#EXCEPTION FOR SUSPECT PRODUCTS
[[ $address =~ ^FF:FF ]] && manufacturer="SIG Unassigned or Noncompliant OEM"
# If no cache try if we have ieee-data
if [ -z "$manufacturer" ] ; then
_temp=$(echo ${address:0:8} | sed 's/://gi')
_found=false
local remote_result=''
if [ ! ${_found} ] && [ -f /var/lib/ieee-data/oui.csv ] ; then
remote_result=$(egrep ",${_temp}," /var/lib/ieee-data/oui.csv | cut -d\, -f3)
_found=true
fi
if [ ! ${_found} ] && [ -f /usr/share/ieee-data/oui.csv ] ; then
remote_result=$(egrep ",${_temp}," /usr/share/ieee-data/oui.csv | cut -d\, -f3)
_found=true
fi
[ -n "$remote_result" ] && echo "${address:0:8} $remote_result" >> .manufacturer_cache
manufacturer="$remote_result"
fi
#IF CACHE DOES NOT EXIST, USE MACVENDORS.COM
if [ -z "$manufacturer" ]; then
local remote_result=$(curl -sL https://api.macvendors.com/${address:0:8} | grep -vi "error" | head -1 | sed 's/[^A-Za-z ]//gi')
#MAKE SURE WE DONT' SCREW UP THE MANUFACTUERE'S FILE
if [[ ! "$remote_result" = *html* ]]; then
[ -n "$remote_result" ] && echo "${address:0:8} $remote_result" >> .manufacturer_cache
manufacturer="$remote_result"
fi
fi
#SET DEFAULT MANUFACTURER
[ -z "$manufacturer" ] && manufacturer="Unknown" && echo "${address:0:8} Unknown" >> .manufacturer_cache
echo "$manufacturer"
fi
}