Awesome
mac_address
Crystal library for working with MAC addresses.
Installation
-
Add the dependency to your
shard.yml
:dependencies: mac_address: github: automatico/mac-address
-
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
- Fork it (https://github.com/automatico/mac-address/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Brad Searle - creator and maintainer