MAC Converter
MAC Address Converter
We’re all dealing with MAC Addresses, some times … there are different formats on different systems. this little script convert it to all formats and you can choise the appropriate ones.
Example
$ maconvert aa:bb:cc:dd:ee:ff
aabbccddeeff
aa:bb:cc:dd:ee:ff
aa-bb-cc-dd-ee-ff
aabb.ccdd.eeff
Script
Copy/Paste will work on OpenBSD, Linux needs some small Modifications (as there is no doas for example …)
doas su -
cat << 'EOFSCRIPT' > /usr/local/bin/maconvert
#!/usr/bin/env bash
# v0.1, 2021, by Christian Henschel
# v0.2, 2021-12-29, Stöge -> add OpenBSD Support & install gawk if needed
if [ OpenBSD == $(uname -s) ]; then
  which gawk &>/dev/null || doas pkg_add gawk
  _awk=$(which gawk)
else
  _awk=$(which awk)
fi
if [ -z "$1" ]; then
  cat <<'EOF'
  no mac address entered, valid format are:
  cafedeadbeef
  cafe.dead.beef
  ca:fe:de:ad:be:ef
  ca-fe-de-ad-be-ef
EOF
  exit 1
else
  mac=$(echo $1 | sed -e 's/[.:-]//g')
  maccolon=$(echo $mac  | $_awk '{gsub(/..\B/,"&:")}1')
  macdash=$(echo $mac  | $_awk '{gsub(/..\B/,"&-")}1')
  macpoint=$(echo $mac | $_awk '{gsub(/....\B/,"&.")}1')
fi
cat <<EOF
  $mac
  $maccolon
  $macdash
  $macpoint
EOF
exit 0
EOFSCRIPT
doas chmod 755 /usr/local/bin/maconvert
maconvert
NJoy!