-
Notifications
You must be signed in to change notification settings - Fork 30
/
oui.sh
38 lines (32 loc) · 923 Bytes
/
oui.sh
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
#!/bin/bash
# oui.sh - IEEE OUI lookup
# phxbandit
help() {
echo "Usage: oui.sh <MAC address>"
exit 1
}
if [ $# -ne 1 ]; then
help
fi
tmp_mac="$1"
ieee='http://standards-oui.ieee.org/oui.txt'
txt="$HOME/oui.txt"
if [[ "$tmp_mac" =~ ^([0-9A-Fa-f]{2}(:|-)){5}[0-9A-Fa-f]{2}$ ]]; then
mac=$(echo "$tmp_mac" | cut -b 1-8 | sed -e 's/\:/-/g' | tr [:lower:] [:upper:])
elif [[ "$tmp_mac" =~ ^[0-9A-Fa-f]{12}$ ]]; then
mac=$(echo "$tmp_mac" | cut -b 1-6 | tr [:lower:] [:upper:])
else
help
fi
if [ ! -f "$txt" ]; then
echo "Retreiving oui.txt from ieee.org..."
wget -q "$ieee" -O "$txt"
else
loc_size=$(ls -l "$txt" | awk '{print $5}')
rem_size=$(curl -sI "$ieee" | grep Content-Length | awk -F': ' '{print $2}' | tr -d '\r')
if [ "$loc_size" != "$rem_size" ]; then
echo "Retreiving oui.txt from ieee.org..."
wget -q "$ieee" -O "$txt"
fi
fi
grep "$mac" "$txt"