macaddr

package
v0.0.0-...-5c98b36 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MulanPSL-2.0 Imports: 7 Imported by: 0

README

macaddr MAC地址工具

在标准库 net.HardwareAddr 的基础上增加了以下 MAC 地址字符串格式解析和反解析

000000000001 (某些厂商的MAC地址格式)
0000-0000-0001 (华为的MAC地址格式)
0000.0000.0001 (思科的MAC地址格式)

收集了常用的函数,以下只列出了经常使用的:

  • Next 返回下一个MAC地址(MAC地址递增1)
  • NewFromMCastIP4 返回 IPv4 组播递增映射的MAC递增
  • NewFromMCastIP6 返回 IPv6 组播递增映射的MAC递增
  • IsMulticast 是组播地址返回true,反之返回false
  • Parse 解析 MAC 地址字符串

Documentation

Overview

package macaddr 解析和反解析MAC地址,下一个MAC地址……

Index

Constants

This section is empty.

Variables

View Source
var (
	Zero  = MAC{0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
	Bcast = MAC{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)

Functions

This section is empty.

Types

type MAC

type MAC net.HardwareAddr

MAC 包装标准库的 net.HardwareAddr 类型 只支持 IEEE 802 MAC-48

func New

func New(hw net.HardwareAddr) MAC

New 包装 net.HardwareAddr

func NewFromMCastIP4

func NewFromMCastIP4(ip4 net.IP) MAC

NewFromMCastIP4 根据组播 IPv4 创建一个开头为 0x01005e 的组播地址

func NewFromMCastIP6

func NewFromMCastIP6(ip6 net.IP) MAC

NewFromMCastIP6 根据组播 IPv4 创建一个开头为 0x3333 的组播地址

func NewRandMAC

func NewRandMAC(oui [3]byte) MAC

NewRandMAC 创建一个随机 MAC 地址

func Parse

func Parse(s string) MAC

Parse 解析字符串为MAC 使用以下格式之一:

00:00:5e:00:53:01
00-00-5e-00-53-01
0000.5e00.5301
0000-5e00-5301
00005e005301

func (MAC) HardwareAddr

func (m MAC) HardwareAddr() net.HardwareAddr

HardwareAddr 返回标准库的类型

func (MAC) IsMulticast

func (m MAC) IsMulticast() bool

IsMulticast 第一位是 0x01 则返回 true

func (MAC) MarshalJSON

func (m MAC) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (MAC) Next

func (m MAC) Next() MAC

Next 返回下一个地址

func (MAC) String

func (m MAC) String() string

String 格式化成字符串

func (MAC) ToCiscoStyle

func (m MAC) ToCiscoStyle() string

ToCiscoStyle 格式化为 xxxx.xxxx.xxxx 风格的字符串

func (MAC) ToHuaweiStyle

func (m MAC) ToHuaweiStyle() string

ToHuaweiStyle 格式化为 xxxx-xxxx-xxxx 风格的字符串

func (MAC) UnmarshalJSON

func (m MAC) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

Jump to

Keyboard shortcuts

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