MAC Address Formatting Conversions

MAC Address Formatting Conversions
NoBlameNetwork January 14, 2019 0 views

My work is now using non-Cisco devices as their gateway, which means I've been spending a decent amount of time converting Standard MAC Addresses to Cisco whenever I need to rundown an issue based on its IP address. 
Because of this I've create the two functions to convert the MACs back and forth for these formats. Below is the script I use and the process for adding it to your .bashrc file.

How it works when you're done
2019 01 14 11 05 16
tc = "to Cisco" from Standard
fc = "from Cisco" to Standard


Script
# ------------------------------------------------------------------------------
_tocisco()
# ------------------------------------------------------------------------------
# Changes standard format MACs to Cisco's amazing '.' format
{
# Use a standard format MAC like 'F4:15:63:C9:30:CD' 
# and this will convert to 'f415.63c9.30cd'
      if [ "$1" != "" ]
      then
       _arg=`echo $1`
        echo $_arg | sed -e 's/\(..\):\(..\)/\1\2/g' | tr ':[:upper:]' '.[:lower:]'
      fi
}
# ------------------------------------------------------------------------------
_fromcisco()
# ------------------------------------------------------------------------------
# Changes Cisco format MACs to standard format
{
# Use a cisco format MAC like 'f415.63c9.30cd'
# this will convert to 'F4:15:63:C9:30:CD'
      if [ "$1" != "" ]
      then
       _arg=`echo $1`
        echo $_arg | tr -d .  | sed 's/.\{2\}/&:/g' | sed 's/.$//'  | tr '[:lower:]' '[:upper:]'
      fi
}

alias fc="_fromcisco"
alias tc="_tocisco"    

This will work on pretty much any linux system.

Use a text editor (vi, or nano/pico) to open your .bashrc file.
If you don't have one you may need to create it.


  • Here I use nano >> nano .bashrc

2019 01 14 11 03 25


  • Then I scroll to the bottom and paste the script from above in at the bottom. 
  • Save and exit nano.

2019 01 14 11 04 35



  • Exit out of your session, and re-enter

2019 01 14 11 04 45


  • Now you can translate to back and forth for these formats quickly.

2019 01 14 11 05 16