-2

I have a bunch of mac addresses which i need to conclude their's vendor (the vendor number is the first 6 digits of a mac address). I am willing to do that by using the built in validMACPrefixMap which maps[3]byte (dec of the first 6 hex digits of the mac) to a string (the vendor). Example of a mac address: "00:50:56:89:a7:4f" which will be converted to [3]byte{0, 80, 86}. (00 => 0, 50 => 80, 56 = >86) and this will eventually retrieve ""VMware, Inc." which is the vendor of that mac address according to the map. The map is shown below.

var ValidMACPrefixMap = validMACPrefixMap
var validMACPrefixMap = map[[3]byte]string{
    [3]byte{0, 0, 0}:       "XEROX CORPORATION",
    [3]byte{0, 0, 1}:       "XEROX CORPORATION",
    [3]byte{0, 0, 2}:       "XEROX CORPORATION",
    [3]byte{0, 0, 3}:       "XEROX CORPORATION",
    [3]byte{0, 0, 4}:       "XEROX CORPORATION",
    [3]byte{0, 0, 5}:       "XEROX CORPORATION",
    [3]byte{0, 0, 6}:       "XEROX CORPORATION",
    [3]byte{0, 0, 7}:       "XEROX CORPORATION",
    [3]byte{0, 0, 8}:       "XEROX CORPORATION",
    [3]byte{0, 0, 9}:       "XEROX CORPORATION",
    [3]byte{0, 0, 10}:      "OMRON TATEISI ELECTRONICS CO.",
    [3]byte{0, 0, 11}:      "MATRIX CORPORATION",
    [3]byte{0, 0, 12}:      "Cisco Systems, Inc",
    [3]byte{0, 0, 13}:      "FIBRONICS LTD.",
    [3]byte{0, 0, 14}:      "FUJITSU LIMITED",
    [3]byte{0, 0, 15}:      "NEXT, INC.",
    [3]byte{0, 0, 16}:      "SYTEK INC.",
    [3]byte{0, 0, 17}:      "NORMEREL SYSTEMES",
    [3]byte{0, 0, 18}:      "INFORMATION TECHNOLOGY LIMITED",
    [3]byte{0, 0, 19}:      "CAMEX",
    [3]byte{0, 0, 20}:      "NETRONIX",
    [3]byte{0, 0, 21}:      "DATAPOINT CORPORATION",
    ..... 
    .....
    .....
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
ibrahimab
  • 1
  • 1
  • Understanding that this is not a task about type conversion but rather about formatting data (sequences of three bytes) as text (a sequence of six characters: two hex digits per byte). There may be multiple approaches to solve this restated problem, but the simplest one appears to be leveraging the facilities provided by the `fmt` package of the standard library. Please read its docs and try to solve the task at hand. – kostix Dec 27 '20 at 19:16
  • What is your question? – Jonathan Hall Dec 27 '20 at 20:40

1 Answers1

0
var sample = "00:50:56:89:a7:4f"
addr, _ := net.ParseMAC(sample) // TODO: error handling
vendor := macs.ValidMACPrefixMap[[3]byte{addr[0], addr[1], addr[2]}] // TODO: check if value is actually available
println("Vendor: ", vendor)
Uku Loskit
  • 40,868
  • 9
  • 92
  • 93