The string is a physical address, then this is split into an array, which then captures the last element of the array. This last element is the actual mac address, then replace all “-” with “:” with the strings package.
For converting cisco mac address format, first remove all “-” then slice the strings up, then join the slice with dot.
package main import ( "fmt" "strings" ) func main() { phyAddr := "Physical Address. . . . . . . . . : 38-00-25-9F-58-30" sSlice := strings.Split(phyAddr, " ") macAddr := sSlice[len(sSlice) -1] ciscoAddr := convCicso(macAddr) fmt.Println("Windows mac address format:",macAddr) fmt.Println("Linux mac address format:", strings.Replace(macAddr, "-", ":", -1)) fmt.Println("Cisco mac address format:", ciscoAddr) } func convCicso(m string) string { c := strings.Replace(m, "-", "", -1) c = c[:4] + "." + c[4:8] + "." + c[8:12] return strings.ToLower(c) }
The result: