Help us shape the future of Go! Take the 2026 Go Developer Survey

macvendors

package module
v0.0.0-...-3fe2f52 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2017 License: MIT Imports: 6 Imported by: 2

README

MAC Vendors

MAC vendors is a Go library which uses the macvendors.co lookup service, to get vendor information of a network device using its MAC address.

Installation

$ go get github.com/umahmood/macvendors

Usage

To get detailed information about a MAC address, use 'Lookup':

package main

import (
    "fmt"
    
    github.com/umahmood/macvendors"
)

func main() {
    vendor := macvendors.New()
    mac, err := vendor.Lookup("28:18:78:6D:64:42")
    if err != nil {
        //...
    }
    fmt.Println(mac.Address)
    fmt.Println(mac.Company)
    fmt.Println(mac.Country)
    fmt.Println(mac.Type)
    fmt.Println(mac.MacPrefix)
    fmt.Println(mac.StartHex)
    fmt.Println(mac.EndHex)
}

Output:

One Microsoft Way,Redmond  Washington  98052-6399,US
Microsoft Corporation
US
MA-L
28:18:78
281878000000
281878FFFFFF

If you are only interested in the vendor name, use the 'Name' method:

name, err := vendor.Name("28:18:78:6D:64:42")
if err != nil {
    //...
}
fmt.Println(name)

Output:

Microsoft Corporation

Testing

  • go version go1.9 darwin/amd64

Documentation

http://godoc.org/github.com/umahmood/macvendors

License

See the LICENSE file for license rights and limitations (MIT).

Documentation

Overview

Package macvendors gets vendor information of a network device using its MAC address.

To get detailed information about a MAC address, use 'Lookup':

package main

import (
    "fmt"

    github.com/umahmood/macvendors"
)

func main() {
    vendor := macvendors.New()
    mac, err := vendor.Lookup("28:18:78:6D:64:42")
    if err != nil {
        //...
    }
    fmt.Println(mac.Address)
    fmt.Println(mac.Company)
    fmt.Println(mac.Country)
    fmt.Println(mac.Type)
    fmt.Println(mac.MacPrefix)
    fmt.Println(mac.StartHex)
    fmt.Println(mac.EndHex)
}

Output:

One Microsoft Way,Redmond  Washington  98052-6399,US
Microsoft Corporation
US
MA-L
28:18:78
281878000000
281878FFFFFF

If you are only interested in the vendor name, use the 'Name' method:

name, err := vendor.Name("28:18:78:6D:64:42")
if err != nil {
    //...
}
fmt.Println(name)

Output:

Microsoft Corporation

Index

Constants

This section is empty.

Variables

View Source
var ErrMACFormat = errors.New("invalid mac format supported formats hex ':' bit '-' dot '.'")

ErrMACFormat invalid formatted MAC address determined by macvendors.co

Functions

This section is empty.

Types

type API

type API struct{}

API instance

func New

func New() *API

New returns a new API instance

func (*API) Lookup

func (m *API) Lookup(macAddress string) (*MAC, error)

Lookup vendor details by MAC address

func (*API) Name

func (m *API) Name(macAddress string) (vendorName string, err error)

Name lookup for vendor name only.

type MAC

type MAC struct {
	*Vendor `json:"result"`
}

MAC instance

type Vendor

type Vendor struct {
	Address   string `json:"address"`
	Company   string `json:"company"`
	Country   string `json:"country"`
	Type      string `json:"type"`
	MacPrefix string `json:"mac_prefix"`
	StartHex  string `json:"start_hex"`
	EndHex    string `json:"end_hex"`
}

Vendor instance

Jump to

Keyboard shortcuts

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