On 7/3/07, ara.t.howard <ara.t.howard / gmail.com> wrote: > > > def mac_address > > return @mac_address if defined? @mac_address > > re = %r<(?:hwaddr|:)\s+((?:[0-9a-f]{1,2}[-:]){5}[0-9a-f]{1,2}) > > \s*$>i > > lines = > > begin > > IO.popen('ifconfig'){|fd| fd.readlines} > > rescue > > IO.popen('ipconfig /all'){|fd| fd.readlines} > > end > > candidates = lines.map{|l| re.match( l )[1] rescue nil }.compact > > @mac_address = candidates.first > > end > > > > can someone give this version a whirl on windows? > $ ruby --version ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-cygwin] $ ruby t.rb t.rb:14: command not found: ifconfig t.rb:11:in `mac_address': undefined method `[]' for nil:NilClass (NoMethodError) from t.rb:14 $ cat t.rb 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 = begin IO.popen('ifconfig'){|fd| fd.readlines} rescue IO.popen('ipconfig /all'){|fd| fd.readlines} end candidates = lines.select{|line| line =~ re} @mac_address = candidates.first[re].strip end puts mac_address IO.popen, it appears, does not raise an exception when the ifconfig command is not found. Strange. Blessings, TwP