From: Robert Dober Date: 2007-07-04T04:21:45+09:00 Subject: Re: mac addr determination On 7/3/07, Alex LeDonne wrote: > On 7/3/07, ara.t.howard wrote: > > > > On Jul 3, 2007, at 9:52 AM, Robert Dober wrote: > > > > > On 7/3/07, ara.t.howard wrote: > > > > > >> > > >> thanks! > > >> > > >> -a > > >> -- > > > Nope on Linux > > > > > > > huh. does for me!? > > > It seems to assume ifconfig is in the $PATH, which on many distros is > not the normal state of affairs for a non-root user (ifconfig tends to > live in /sbin, I think). You are right and it might be a point to note for the code in general. However I did not do something stupid for once ;), this is the output which just does not match the original regexp ( I run as root and stepped the original code through irb ) eth0 Link encap:Ethernet HWaddr 00:11:xx:xx:xx:xx What distro are you running I tested on a Slax and a Debian Sarge? Could you test my reg or give the line to match so that Ara can adapt please. > > -A > > > > > 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 > > > > > > but not tested on Windows > > > HTH > > > Robert > > > -- > > > > can someone give this version a whirl on windows? Home now I just run it, seems to work fine. Cheers Robert > > > > -a > > -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck