1
0
mirror of https://github.com/aquatix/dotfiles.git synced 2025-12-06 21:45:10 +01:00

Nifty little MAC-address lookup script

This commit is contained in:
2022-04-11 16:20:53 +02:00
parent e9957332e5
commit d9bbe483ba

36
bin/mac.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Stolen from https://raw.githubusercontent.com/Cybertinus/macvendor_extractor/master/mac.sh
##########
# CONFIG #
##########
# Download from http://standards-oui.ieee.org/oui/oui.txt
ouilocation="${HOME}/.dot/oui.txt"
#################
# ACTUAL SCRIPT #
#################
if [ ! -f "${ouilocation}" ] ; then
echo 'OUI location can not be found. Have you updated the config?' 1>&2
exit 1
fi
if [ -z "${1}" ] ; then
echo 'No mac address specified, please do so as first argument' 1>&2
exit 2
fi
macaddress="$(echo "${1}" | sed -e 's/[-.:]//g' | tr '[:lower:]' '[:upper:]')"
macaddress="${macaddress:0:6}"
echo -n "${1} = "
vendor="$(awk "/^${macaddress}/ {print substr(\$0,index(\$0,\$4))}" "${ouilocation}")"
if [ -z "${vendor}" ] ; then
echo "Not specified in ${ouilocation}"
else
echo "${vendor}"
fi