2 # mac-to-devinfo - MAC IEEE and custom information
3 # Copyright (C) 2009 Daniel Dickinson
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 UCIFUNC
=/usr
/lib
/mac-to-devinfo
/devinfo-functions.sh
21 OVERRIDETABLE
=mactodevinfo
25 OUIURL
=http
://standards.ieee.org
/regauth
/oui
/oui.txt
26 IABURL
=http
://standards.ieee.org
/regauth
/oui
/iab.txt
28 OUIDIR
=/var
/cache
/mac-to-devinfo
30 OUIFILE
=$OUIDIR/oui.txt
31 IABFILE
=$OUIDIR/iab.txt
33 UCIDEVDB
=/usr
/share
/mac-to-devinfo
34 UCISTATE
="$(mktemp -t)"
39 if [ "$1" == "-x" ]; then
41 if [ -z "$PORT" ]; then
42 echo "-x without the port"
43 echo "Usage: $0 [-x port] MAC-address"
52 if [ -z "$MAC" ]; then
53 echo "Unknown MAC address | Unknown | unknown | unknown | unknown"
57 MAC
=$
(echo $MAC |
sed -e 's/^\([0-9]\):/0\1:/g' |
sed -e 's/:\([0-9]\)$/:0\1/g' |
sed -e 's/:\([0-9]\):/:0\1:/g')
61 config_get name
"$cfg" name
62 config_get maclow
"$cfg" maclow
63 config_get machigh
"$cfg" machigh
64 config_get vendor
"$cfg" vendor
65 config_get devtype
"$cfg" devtype
66 config_get model
"$cfg" model
67 config_get ouiowneroverride
"$cfg" ouiowner
68 LOW
=$
(echo $maclow |
sed -e 's/://g')
69 HIGH
=$
(echo $machigh |
sed -e 's/://g')
70 if [ -z "$LOW" ] ||
[ -z "$HIGH" ] ||
[ -n "$(echo $LOW | grep -E -v '^[0-9A-Fa-f]{12}$')" ] ||
[ -n "$(echo $HIGH | grep -E -v '^[0-9A-Fa-f]{12}$')" ]; then
71 echo "Invalid mac range for $name: $ouiowneroverride $vendor $devtype $model : $LOW-$HIGH" >&2
75 LOWMSB
=$
(expr substr
"$LOW" 1 6)
76 LOWLSB
=$
(expr substr
"$LOW" 7 6)
77 HIGHMSB
=$
(expr substr
"$HIGH" 1 6)
78 HIGHLSB
=$
(expr substr
"$HIGH" 7 6)
80 if [ -z "$LOWMSB" ] ||
[ -z "$LOWLSB" ] ||
[ -z "$HIGHMSB" ] ||
[ -z "$HIGHLSB" ]; then
81 echo "Error splitting database address strings"
85 MACMSB
=$
(expr substr
"$MACNUM" 1 6)
86 MACLSB
=$
(expr substr
"$MACNUM" 7 6)
88 if [ -z "$MACMSB" ] ||
[ -z "$MACLSB" ]; then
89 echo "Error spliiting mac address string"
93 if [ -n "$ouiowneroverride" ]; then
94 OUIOWNER
="$ouiowneroverride"
96 if [ $
((0x
$MACMSB)) -ge $
((0x
$LOWMSB)) ] && [ $
((0x
$MACMSB)) -le $
((0x
$HIGHMSB)) ]; then
97 if [ $
((0x
$MACLSB)) -ge $
((0x
$LOWLSB)) ] && [ $
((0x
$MACLSB)) -le $
((0x
$HIGHLSB)) ]; then
98 if [ "$PORT" == "5060" ]; then
99 if [ "$vendor" == "Vertical Communications" ]; then
104 if [ "$PORT" == "6060" ]; then
105 if [ "$vendor" == "Vertical Communications" ]; then
107 model
="Xcelerator IP"
110 if [ -n "$OUTSTRING" ]; then
111 echo "ERROR: We already have found information '$OUTSTRING'" >&2
112 echo -n "and now we have: " >&2
113 echo "$MAC | $OUIOWNER | $vendor | $devtype | $model" >&2
116 echo "$MAC | $OUIOWNER | $vendor | $devtype | $model"
124 if [ ! -r "$OUIFILE" ] ||
[ ! -r "$IABFILE" ]; then
125 echo "Missing IEEE Registration Authority Database. Please run prep-devinfo"
129 OUI
="$(echo $MAC | cut -f1-3 -d: | sed -e 's/:/-/g' | tr abcdef ABCDEF )"
131 OUIOWNER
="$(cat $OUIFILE | grep $OUI | tr -s '\t' | cut -f2- -d"$
(printf '\t')" )"
133 if [ -z "$OUIOWNER" ] ||
[ "$OUIOWNER" = "IEEE REGISTRATION AUTHORITY" ]; then
134 if [ -n "$(cat $IABFILE | grep $OUI)" ]; then
135 LOWRANGE
="$(echo $MAC | cut -f4-6 -d: | sed -e 's/://g' | tr abcdef ABCDEF )"
136 for range
in $
(cat $IABFILE |
grep -E '[0-9A-F]{6}\-[0-9A-F]{6}' |cut
-f1 -d"$(printf '\t')" ); do
137 LOW
="$(echo $range | cut -f1 -d- )"
138 HIGH
="$(echo $range | cut -f2 -d- )"
139 if [ -z "$LOW" ] ||
[ -z "$HIGH" ]; then
140 echo "Error parsing IAB table"
144 LOWMSB
=$
(expr substr
"$LOW" 1 6)
145 LOWLSB
=$
(expr substr
"$LOW" 7 6)
146 HIGHMSB
=$
(expr substr
"$HIGH" 1 6)
147 HIGHLSB
=$
(expr substr
"$HIGH" 7 6)
149 if [ -z "$LOWMSB" ] ||
[ -z "$LOWLSB" ] ||
[ -z "$HIGHMSB" ] ||
[ -z "$HIGHLSB" ]; then
150 echo "Error splitting registration authority IAB address strings"
154 MACMSB
=$
(expr substr
"$LOWRANGE" 1 6)
155 MACLSB
=$
(expr substr
"$LOWRANGE" 7 6)
157 if [ -z "$MACMSB" ] ||
[ -z "$MACLSB" ]; then
158 echo "Error splitting mac address string"
161 if [ $
((0x
$MACMSB)) -ge $
((0x
$LOWMSB)) ] && [ $
((0x
$MACMSB)) -le $
((0x
$HIGHMSB)) ]; then
162 if [ $
((0x
$MACLSB)) -ge $
((0x
$LOWLSB)) ] && [ $
((0x
$MACLSB)) -le $
((0x
$HIGHLSB)) ]; then
163 OUIOWNER
="$(cat $IABFILE | grep "$LOW-$HIGH" | tr -s '\t' | cut -f3- -d"$
(printf '\t')" )"
171 if [ -z "$OUIOWNER" ]; then
172 OUIOWNER
="Unknown Organization"
175 MACNUM
="$(echo $MAC |sed -e 's/://g' | tr ABCDEF abcdef )"
177 UCI
="$UCIBIN -c $UCIDEVDB"
179 DEVSTRING
=$
(config_foreach parse_override mactodevinfo
)
181 SAVEDEVSTRING
="$DEVSTRING"
183 UCI
="$UCIBIN -c $UCICONFIG"
184 config_load
$OVERRIDETABLE
185 DEVSTRING
=$
(config_foreach parse_override mactodevinfo
)
187 if [ -z "$DEVSTRING" ]; then
188 if [ -z "$SAVEDEVSTRING" ]; then
189 echo "$MAC | $OUIOWNER | unknown | unknown | unknown"
191 echo "$SAVEDEVSTRING"