MAC Address & Prefix Utility for Go

macaddr


MAC Address & Prefix Utility for Go

GitHub Workflow Status Docs Code Coverage Go Report Card

Installation

go get -d github.com/thatmattlove/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

Owner
Matt Love
I make boring things in interesting ways
Matt Love
Similar Resources

Take an IP address and quickly get the reverse PTR

FlipIP Just a little quick app to take an IP (or set of IPs), and convert them to reverse IP pointers Example: $ flipip 1.2.3.4 4.3.2.1.in-addr.arpa.

Feb 27, 2022

Shrek is a vanity .onion address generator written in Go.

Shrek is a vanity .onion address generator written in Go.

Shrek Shrek is a vanity .onion address generator written in Go. Usage (CLI) Shrek compiles to a single binary that can be used on the CLI. To build an

Aug 16, 2022

checkip is a CLI tool and library that checks an IP address using various public services.

checkip is a CLI tool and library that checks an IP address using various public services.

checkip is a CLI tool and library that checks an IP address using various public services.

Dec 20, 2022

A small library to detect if an IP address is close to yours

go-geofence A small library to detect if an IP address is close to yours or another of your choosing using https://ipstack.com/ Usage First you will n

Aug 10, 2022

A small tool used to correspond to the IP address according to the name, id, and network alias of the docker container, which can be run as a DNS server

A small tool used to correspond to the IP address according to the name, id, and network alias of the docker container, which can be run as a DNS server

Apr 4, 2022

Gopi - Simple API for get geo information about your IP Address, Build by go-fiber

gopi Simple API to get information from your IP Address Idea This idea come from IP zxq and literaly i clone it How to download GeoIP2 ? Remember to c

May 27, 2022

Automatically update your Windows hosts file with the WSL2 VM IP address

Automatically update your Windows hosts file with the WSL2 VM IP address

Jan 9, 2023

Just another "what is my IP address" service, including geolocation and headers information

What is my IP address What is my IP address Features Endpoints Build Usage Examples Run a default TCP server Run a TLS (HTTP/2) server only Run a defa

Nov 21, 2022

Project helps to identify the network, broadcast address and no of possible hosts

network_identifier Project helps to identify the network, broadcast address and no of possible hosts for Ipv4 address To use it directly as a go file

Dec 3, 2021
Related tags
generate Wireguard keypairs with a given prefix string

wireguard-vanity-address Generate Wireguard keypairs with a given prefix string. The Wireguard VPN uses Curve25519 keypairs, and displays the Base64-e

Nov 9, 2022
A rule based proxy For Mac base on Clash.
A rule based proxy For Mac base on Clash.

ClashX A rule based proxy For Mac base on Clash. ClashX 旨在提供一个简单轻量化的代理客户端,如果需要更多的定制化,可以考虑使用 CFW Mac 版 Features HTTP/HTTPS and SOCKS protocol Surge lik

Dec 26, 2022
A tool helps connect to your AriPods when sound playing in your Mac

Auto connect to airpods this tool helps connect to your AriPods when sound playing in your Mac. dependencenes SwitchAudioSource $ brew install switcha

Dec 9, 2021
Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump.
Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump.

Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump. Some of its features include: Unde

Feb 26, 2022
Go pkg for returning your public facing IP address.

#publicip This package returns the public facing IP address of the calling client (a la https://icanhazip.com, but from Go!) Author James Polera james

Nov 21, 2022
Network address types

netaddr What This is a package containing a new IP address type for Go. See its docs: https://pkg.go.dev/inet.af/netaddr Motivation See https://tailsc

Dec 28, 2022
A simple tool for retrieving a request's IP address on the server.

reqip A simple tool for retrieving a request's IP address on the server. Inspired from request-ip Installation Via go get go get github.com/mo7zayed/r

Oct 26, 2022
An Yggdrasil address miner in Go

SimpleYggGen-Go This program reimplements SimpleYggGen in Go, importing the original Yggdrasil code for generating keys and utilizing multiple CPU thr

Apr 21, 2022
Serverless Lightning Address server

Addressless Put a Lightning Address "server" on a serverless host like Vercel. The code is heavily borrowed from satdress, minus the federated part. T

Aug 29, 2022
⚡ 🖥️ 👾 Host your own Lightning Address on LND

⚡ ??️ ?? Host your own Lightning Address on LND Lighting Wallets like BlueWallet, Blixt and many more allow us to send sats to Lighting Addresses like

Dec 22, 2022