Code Monkey home page Code Monkey logo

go-macaddr's Introduction

macaddr

MAC Address & Prefix Utility for Go

Docs

GitHub Actions Workflow Status Test Coverage Go Report Card

Installation

go get -d go.mdl.wtf/go-macaddr/go-macaddr

Usage

Single MAC Address

mac, err := macaddr.ParseMACAddress("00:00:5e:00:53:ab")
if err != nil {
    panic(err)
}

mac.ByteString()
// {0,0,94,0,83,171}
mac.Clone()
// MACAddress{0,0,0x5e,0,53,0xab}
mac.Dashes()
// 00-00-5e-00-53-ab
mac.Dots()
// 0000.5e00.53ab
mac.Equal(MACAddress{0,0,0x5e,0,53,0xab})
// true
mac.Format("xxx_xxx_xxx_xxx")
// 000_05e_005_3ab
mac.GEqual(MACAddress{0,0,0x5e,0,53,0xac})
// false
mac.Greater(MACAddress{0,0,0x5e,0,53,0xaa})
// true
mac.Int()
// 1577079723
mac.LEqual(MACAddress{0,0,0x5e,0,53,0xac})
// true
mac.Lesser(MACAddress{0,0,0x5e,0,53,0xaa})
// false
mac.Mask(MACAddress{0xff,0xff,0xff,0xff,0xff,0})
// MACAddress{0,0,0x5e,0,0x53,0}
mac.Next()
// MACAddress{0,0,0x5e,0,0x53,0xac}
mac.NoSeparators()
// 00005e0053ab
mac.OUI()
// 00:00:5e
mac.Previous()
// MACAddress{0,0,0x5e,0,0x53,0xaa}
mac.String()
// 00:00:5e:00:53:ab

MAC Prefix

mac, prefix, err := macaddr.ParseMACPrefix("00:00:5e:00:00:00/24")

if err != nil {
    panic(err)
}

prefix.Count()
// 16777216
prefix.First()
// MACAddress{0,0,0x5e,0,0,0}
iter := prefix.Iter()
for iter.Next() {
    iter.Value()
}
// MACAddress{0,0,0x5e,0,0,0}
// MACAddress{0,0,0x5e,0,0,1}
// MACAddress{0,0,0x5e,0,0,2}
// ...
match, err := prefix.Match("00:00:5e:01:23:45")
match.String()
// 00:00:5e:00:00:00/24
match, err = prefix.Match("00:00:5f:01:23:45")
err.Error()
// '00:00:5f:01:23:45' is not contained within MACPrefix 00:00:5e:00:00:00/24
prefix.OUI()
// 00:00:5e
prefix.PrefixLen()
// 24
prefix.String()
// 00:00:5e:00:00:00/24
prefix.WildcardMask()
// MACPrefix{0,0,0,0xff,0xff,0xff}

Roadmap

Depending on if others find this library useful, EUI-64 support may be added. Please open an issue if you would find this helpful.

GitHub

go-macaddr's People

Contributors

thatmattlove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.