From: Rob Biedenharn Date: 2007-07-04T05:20:49+09:00 Subject: Re: mac addr determination [current winner] On Jul 3, 2007, at 3:46 PM, ara.t.howard wrote: > On Jul 3, 2007, at 1:36 PM, Jeff Barczewski wrote: >> yes, that's a winner. >> >> works on win xp >> works on gentoo linux > > 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 > cmds = '/sbin/ifconfig', '/bin/ifconfig', 'ifconfig', > 'ipconfig /all' > > null = test(?e, '/dev/null') ? '/dev/null' : 'NUL' > > lines = nil > cmds.each do |cmd| > stdout = IO.popen("#{ cmd } 2> #{ null }"){|fd| > fd.readlines} rescue next > next unless stdout and stdout.size > 0 > lines = stdout and break > end > raise "all of #{ cmds.join ' ' } 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 > > -a > -- > we can deny everything, except that we have the possibility of > being better. simply reflect on that. > h.h. the 14th dalai lama Well, it works on Mac OS X 10.4.10 except that it tells me the mac of the en0 (which isn't being used, nothing's plugged in!) rather than the en1 of the wireless adapter (which is active). Is that what you're expecting? -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com