oui

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

README

GitHub Actions Go Report Card Codecov GoDoc

Vendor lookup from MAC prefixes

A Go module that provides methods to lookup the Vendor string of an Organizationally Unique Identifier. For Ethernet MACs the OUI is encoded in the first 24 bits.

Vendor lookup is done statically using generated code. Code is generated based in the IEEE registration database.


Usage

package main

import (
	"fmt"
	"net"

	"github.com/endobit/oui"
)

func main() {
	const addr = "00:00:0f:01:02:03"

	// Lookup the vendor of an Ethernet MAC.

	fmt.Println(oui.Vendor(addr))

	// Or, lookup the vendor of a net.HardwareAddr.

	mac, err := net.ParseMAC(addr)
	if err != nil {
		fmt.Println("%q not a mac", addr)
		panic(err)
	}

	fmt.Println(oui.VendorFromMAC(mac))
}

Building

This package uses mage.

Type mage for a list of targets. mage build will regenerate the static OUI data.

Documentation

Overview

Package oui provides methods to lookup the Vendor string of an Organizationally Unique Identifier. For Ethernet MACs the OUI is the first 24 bits.

Vendor lookup in performed on a code generated data set. The static data is generated from the CSV file maintained by the IEEE. (https://standards-oui.ieee.org/oui/oui.csv).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Vendor

func Vendor(s string) string

Vendor returns the Vendor of the OUI s, or the empty string if not found. The value s can be either just the OUI or a mac address, it can also include or exclude the ":" delimiters. Any of the following are valid inputs:

0A:0B:0C
0a:0b:0c
0A0B0C
0a0b0c
0A:0B:0C:01:02:03
0a:0b:0c:01:02:03
0A0B0C010203
0a0b0c010203

func VendorFromMAC

func VendorFromMAC(hw net.HardwareAddr) string

VendorFromMAC returns the hardware vendor of a net.HardwareAddr. Both 48 and 64 bits addresses are valid, as the OUI is the first 24 bits of both.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL