new: updated mac vendor lookup with IEEE datasets

This commit is contained in:
Simone Margaritelli 2024-08-08 12:47:59 +02:00
commit 5858743b6e
9 changed files with 104569 additions and 84588 deletions

View file

@ -1,28 +1,21 @@
package network
import (
"fmt"
"strings"
"math/big"
)
var manuf = #MAP#
func ManufLookup(mac string) string {
macHex := strings.Replace(mac, ":", "", -1)
macInt := new(big.Int)
macHex := strings.ToUpper(strings.Replace(mac, ":", "", -1))
macLen := len(macHex)
if _, ok := macInt.SetString(macHex, 16); ok == false {
return ""
}
for mask := uint(0); mask < 48; mask++ {
shifted := new(big.Int).Rsh(macInt, mask)
key := fmt.Sprintf("%d.%s", mask, shifted)
if vendor, found := manuf[key]; found {
return vendor
}
}
for offset := macLen; offset >= 2; offset -= 2 {
part := macHex[0:offset]
if vendor, found := manuf[part]; found {
return vendor
}
}
return ""
}
}