module Cornflake::MacAddress

Constants

RE

Public Class Methods

find() click to toggle source
# File lib/cornflake/mac.rb, line 7
def self.find
  cmds = '/sbin/ifconfig', '/bin/ifconfig', 'ifconfig', 'cat /sys/class/net/*/address'

  cmds.each do |cmd|
    mac = parse_mac_output(`#{cmd}`)
    return mac if mac
  end

  # Not found; randomize a mac address
  SecureRandom.hex(6).scan(/.{2}/).join(':')
end

Private Class Methods

parse_mac_output(output) click to toggle source
# File lib/cornflake/mac.rb, line 20
def self.parse_mac_output(output)
  output.split(/\n/).each do |line|
    mac = line[RE]
    return mac.strip if mac
  end
end