------ art_106721_29926918.1183490840819
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
def mac_address
return @mac_address if defined? @mac_address
re %r/[^:\-](?:[0-9A-Za-z][0-9A-Za-z][:\-]){5}[0-9A-Za-z][0-9A-Za-z][^:\-]/o
lines il
cmds /sbin/ifconfig', '/bin/ifconfig', 'ifconfig',
'ipconfig /all'
cmds.each do |cmd|
begin
stdout O.popen(cmd){|fd| fd.readlines}
rescue
stdout il
end
next unless stdout and stdout.size > 0
lines tdout and break
end
raise "failed" unless lines
candidates ines.select{|line| line re}
raise 'no mac address candidates' unless candidates.first
maddr andidates.first[re]
raise 'no mac address found' unless maddr
@mac_address addr.strip
end
puts mac_address
Note: I needed to wrap with begin rescue to get it to work on windows
- works on gentoo linux
- works on windows
--
Jeff Barczewski, MasterView core team
Inspired Horizons Ruby on Rails Training and Consultancy
http://inspiredhorizons.com/
------ art_106721_29926918.1183490840819--