From: Jeff Barczewski Date: 2007-07-04T04:27:18+09:00 Subject: Re: mac addr determination ------=_Part_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 = nil cmds = '/sbin/ifconfig', '/bin/ifconfig', 'ifconfig', 'ipconfig /all' cmds.each do |cmd| begin stdout = IO.popen(cmd){|fd| fd.readlines} rescue stdout = nil end next unless stdout and stdout.size > 0 lines = stdout and break end raise "failed" unless lines candidates = lines.select{|line| line =~ re} raise 'no mac address candidates' unless candidates.first maddr = candidates.first[re] raise 'no mac address found' unless maddr @mac_address = maddr.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/ ------=_Part_106721_29926918.1183490840819--