mac-address

Crystal Lib for working with MAC addresses

mac_address

Crystal library for working with MAC addresses.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      mac_address:
        github: automatico/mac-address
    
  2. Run shards install

Usage

# Import the `mac_address` lib
require "mac_address"

# Create and instance of `MacAddress::MAC`
mac = MacAddress::MAC.new("11:bb:cc:ee:44:55")

Methods

Return the bare MAC address without any delimiters.

mac.bare # => "11bbccee4455"

Return the MAC address in EUI notation.

mac.eui # => "11-bb-cc-ee-44-55"

Return the MAC address in hex notation.

mac.hex # => "11:bb:cc:ee:44:55"

Return the MAC address in dot notation.

mac.dot # => "11bb.ccee.4455"

Return the MAC address as an integer.

mac.int # => 19498294723669

Return the MAC address as an array of bits.

mac.bits # => ["0001", "0001", "1011", "1011", "1100", "1100", "1110", "1110", "0100", "0100", "0101", "0101"]

Return the binary representation for a MAC.

mac.binary # => "000100011011101111001100111011100100010001010101"

Returns the MAC address in an array of octets.

mac.octets # => ["11", "bb", "cc", "ee", "44", "55"]

Return the vendor portion of the MAC address.

mac.oui # => 11bbcc

Return the nic portion of the MAC address.

mac.nic # => ee4455

Returns true if MAC is a broadcast address.

mac.broadcast? # => false

Returns true if MAC is a multicast address.

mac.multicast? # => false

Returns true if MAC is a unicast address.

mac.unicast? # => true

Convert MAC address into an IPv6 link local address.

mac.ipv6_link_local # => fe80::13bb:ccff:feee:4455

Convert MAC address into an EUI-64 MAC address.

mac.eui64 # => 13:bb:cc:ff:fe:ee:44:55

Contributing

  1. Fork it (https://github.com/automatico/mac-address/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

mac-address

Owner
Statistic
  • 2
  • 0
  • 0
  • 1
  • 0
  • about 3 years ago
  • August 17, 2021
License

MIT License

Links
Synced at

Sun, 22 Dec 2024 12:59:22 GMT

Languages