maclookup

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: MIT Imports: 11 Imported by: 0

README

maclookup-go

Build Status Go Report Card codecov

A Go library for interacting with MACLookup's API v2. This library allows you to:

  • Get full info (MAC prefix, company name, address and country) of a MAC address
  • Get Company name by MAC

Installation

You need a working Go environment.

 go get github.com/logocomune/maclookup-go

##Getting Started

package main

import (
	"log"

	"github.com/logocomune/maclookup-go"
)

func main() {
	client := maclookup.New()
    
	r, err := client.CompanyName("000000")

	if err != nil {
		log.Fatal(err)
	}

	log.Println("MAC found in database:", r.Found)
	log.Println("MAC is private (no company name):", r.IsPrivate)
	log.Println("Company name:", r.Company)
	log.Println("Api response in: ", r.RespTime)
	log.Println("Rate limits - remaining request for current time window:", r.RateLimit.Remaining)
	log.Println("Rate limits - next reset", r.RateLimit.Reset)

}


Use custom timout
    client := maclookup.New()
    client.WithTimeout(10*time.Second) 
API Key

Get an API Key here

    client := maclookup.New()
	client.WithAPIKey("an_api_key")

Example

Documentation

Overview

Package maclookup implements the MACLookup API v2.

Api documentation: https://maclookup.app/api-v2/documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadAPIKey

type BadAPIKey struct {
	Err error
}

func (*BadAPIKey) Error

func (c *BadAPIKey) Error() string

func (*BadAPIKey) Unwrap

func (c *BadAPIKey) Unwrap() error

type BadAPIRequest

type BadAPIRequest struct {
	Err error
}

func (*BadAPIRequest) Error

func (c *BadAPIRequest) Error() string

func (*BadAPIRequest) Unwrap

func (c *BadAPIRequest) Unwrap() error

type BadAPIResponse

type BadAPIResponse struct {
	Err error
}

func (*BadAPIResponse) Error

func (c *BadAPIResponse) Error() string

func (*BadAPIResponse) Unwrap

func (c *BadAPIResponse) Unwrap() error

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New() *Client

New creates a new client for maclookup.app API.

func (Client) CompanyName

func (c Client) CompanyName(mac string) (ResponseVendorName, error)

CompanyName returns company name from API.

Example
//Prevent rate limits error
time.Sleep(time.Millisecond * 550)

client := New()
r, err := client.CompanyName("000000")
fmt.Println(err)
fmt.Printf("%s", r.Company)
Output:

<nil>
XEROX CORPORATION

func (Client) Lookup

func (c Client) Lookup(mac string) (ResponseMACInfo, error)

Lookup retrieve MAC information from API.

Example
//Prevent rate limits error
time.Sleep(time.Millisecond * 550)

client := New()
r, err := client.Lookup("000000")
fmt.Println(err)
fmt.Printf("%+v", r.MACInfo)
Output:

<nil>
{Found:true MacPrefix:000000 Company:XEROX CORPORATION Address:M/S 105-50C, WEBSTER NY 14580, US Country:US BlockStart:000000000000 BlockEnd:000000FFFFFF BlockSize:16777215 BlockType:MA-L Updated:2015-11-17 IsRand:false IsPrivate:false}

func (*Client) WithAPIKey

func (c *Client) WithAPIKey(apiKey string)

WithAPIKey adds apiKey to client.

func (*Client) WithPrefixURI

func (c *Client) WithPrefixURI(prefixURI string)

WithPrefixURI changes the default API prefix url.

func (*Client) WithTimeout

func (c *Client) WithTimeout(timeout time.Duration)

WithTimeout defines a new timeout value for every request.

type CompanyInfo

type CompanyInfo struct {
	Found     bool
	IsPrivate bool
	Company   string
}

type HTTPClientError

type HTTPClientError struct {
	Err error
}

func (*HTTPClientError) Error

func (c *HTTPClientError) Error() string

func (*HTTPClientError) Unwrap

func (c *HTTPClientError) Unwrap() error

type MACInfo

type MACInfo struct {
	Found      bool
	MacPrefix  string
	Company    string
	Address    string
	Country    string
	BlockStart string
	BlockEnd   string
	BlockSize  int
	BlockType  string
	Updated    string
	IsRand     bool
	IsPrivate  bool
}

type RateLimit

type RateLimit struct {
	Limit     int64
	Remaining int64
	Reset     time.Time
}

type RateLimitsExceeded

type RateLimitsExceeded struct {
	Limit int64
	Reset time.Time
	Err   error
}

func (*RateLimitsExceeded) Error

func (c *RateLimitsExceeded) Error() string

type ResponseMACInfo

type ResponseMACInfo struct {
	RespTime time.Duration
	RateLimit
	MACInfo
}

type ResponseVendorName

type ResponseVendorName struct {
	RespTime time.Duration
	RateLimit
	CompanyInfo
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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