module Mac
Constants
- VERSION
Attributes
mac_address[RW]
Accessor for the system's first MAC address, requires a call to address first
Public Class Methods
address()
click to toggle source
Discovers and returns the system's MAC addresses. Returns the first MAC address, and includes an accessor list for the remaining addresses:
Mac.addr # => first address Mac.addrs # => all addresses
# File lib/macaddr.rb, line 58 def address @mac_address ||= addresses.first end
Also aliased as: addr
addresses()
click to toggle source
# File lib/macaddr.rb, line 62 def addresses @mac_addresses ||= from_getifaddrs || [] end
Also aliased as: addrs
dependencies()
click to toggle source
# File lib/macaddr.rb, line 33 def Mac.dependencies { } end
description()
click to toggle source
# File lib/macaddr.rb, line 38 def Mac.description 'cross platform mac address determination for ruby' end
version()
click to toggle source
# File lib/macaddr.rb, line 29 def Mac.version ::Mac::VERSION end
Private Class Methods
from_getifaddrs()
click to toggle source
# File lib/macaddr.rb, line 78 def from_getifaddrs return unless Socket.respond_to? :getifaddrs interfaces = Socket.getifaddrs.select do |addr| addr.addr && addr.addr.pfamily == INTERFACE_PACKET_FAMILY end if Socket.const_defined? :PF_LINK then interfaces.map do |addr| addr.addr.getnameinfo end.flatten.select do |m| !m.empty? end elsif Socket.const_defined? :PF_PACKET then interfaces.map do |addr| addr.addr.inspect_sockaddr[/hwaddr=([\h:]+)/, 1] end.select do |mac_addr| mac_addr != '00:00:00:00:00:00' end end end