#!/usr/bin/env bash

prefixesfile=/home/einar/ownCloud/Datadumper/master_oui.txt

if [[ ! -f $prefixesfile ]]; then
  echo "Could not find MAC prefixes file $prefixesfile, please download from https://raw.githubusercontent.com/Ringmast4r/OUI-Master-Database/main/LISTS/master_oui.txt and save to some suitable place and update script accordingly"
  exit 1
fi

hexregex="^[[:xdigit:]]{6,12}$"

prefix=${1//:/}      # strip :
prefix=${prefix//-/} # strip -
prefix=${prefix//./} # strip .
prefix=${prefix^^}   # uppercase

if [[ $prefix =~ $hexregex ]]; then
  prefix=${prefix:0:6} # we only need first 6 chars
  grep "$prefix" "$prefixesfile"
else
  echo "Input parameter does not resemble a MAC address"
  exit 1
fi
