Last active
April 26, 2017 18:24
-
-
Save meoso/88587a8afcabaf92ef93bb14366f6a5a to your computer and use it in GitHub Desktop.
MAC address lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Require 1 parameter | |
if [ $# -lt 1 ] || [[ ${#1} -lt 6 ]] || [[ "$1" = *"-h"* ]] ; then | |
echo "MAC lookup tool by njd" | |
echo "Usage: ${0##*/} MAC" | |
echo | |
echo "Dependencies: curl, grep, awk, sed, cut" | |
echo "Automatically downloads http://standards-oui.ieee.org/oui.txt" | |
echo | |
echo "Required parameter - MAC address in any of the following formats:" | |
echo " ##:##:##[:##:##:##]" | |
echo " ##-##-##[-##-##-##]" | |
echo " ######[######]" | |
echo | |
echo "example usage: ${0##*/} 8b:ad:de:ad:be:ef" | |
echo "example usage: ${0##*/} 8b-ad-de-ad-be-ef" | |
echo "example usage: ${0##*/} 8baddeadbeef" | |
echo "example usage: ${0##*/} 8b:ad:de" | |
echo "example usage: ${0##*/} 8b-ad-de" | |
echo "example usage: ${0##*/} 8badde" | |
echo | |
exit 1 | |
fi | |
#bname=$(basename "$0") #${0##*/} | |
dname=$(dirname "$0") | |
cd "$dname" || exit 1 | |
touch -d "$(date -d '30 days ago')" 30DAYSAGO | |
if ! [ -f oui.txt ] || [ oui.txt -ot 30DAYSAGO ] | |
then | |
echo "Downloading IEEE MA-L (MAC Vendors)." | |
curl --progress-bar --compressed --remote-name http://standards-oui.ieee.org/oui.txt | |
grep -F "(base 16)" oui.txt | awk '{$2=$3="" ; print $0}' | awk -F" " '{print $1 ":" $2}' > tempOUI | |
mv tempOUI oui.txt | |
fi | |
rm 30DAYSAGO>/dev/null 2>&1 | |
mac=$1 | |
mac=$(echo "$mac" | sed 's/-//g' | sed 's/\://g' | cut -c1-6 | awk '{print toupper($0)}') | |
vendor=$(grep -m 1 ^"$mac" oui.txt | awk -F':' '{print $2}') | |
echo "$mac : $vendor" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment