can someone run this on windows and let me know if it works?
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
thanks!
-a
···
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
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
···
On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
> <snip>
>>
>> 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).
-A
···
On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
On Jul 3, 2007, at 9:52 AM, Robert Dober wrote:
> 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
>
> but not tested on Windows
> HTH
> Robert
> --
Yes, it is not in my user path for gentoo linux either. It is in my /sbin
directory which my non-admin users don't normally have in their path.
···
On 7/3/07, Alex LeDonne <aledonne.listmail@gmail.com> wrote:
On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
>
> On Jul 3, 2007, at 9:52 AM, Robert Dober wrote:
>
> > On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
> > <snip>
> >>
> >> 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).
--
Jeff Barczewski, MasterView core team
Inspired Horizons Ruby on Rails Training and Consultancy http://inspiredhorizons.com/
>
> > <snip>
> >>
> >> 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
···
On 7/3/07, Alex LeDonne <aledonne.listmail@gmail.com> wrote:
On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
> On Jul 3, 2007, at 9:52 AM, Robert Dober wrote:
> > On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
>
> -a
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
latest version. can everyone test on various platforms and report results and/or patch?
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|
stdout = IO.popen('ifconfig'){|fd| fd.readlines}
next unless stdout and stdout.size > 0
lines = stdout and break
end
raise 'ifconfig 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
i promise to post this when we're done so we all have it.
kind regards.
-a
···
On Jul 3, 2007, at 12:28 PM, Jeff Barczewski wrote:
Yes, it is not in my user path for gentoo linux either. It is in my /sbin
directory which my non-admin users don't normally have in their path.
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
testara.rb:9:in `popen': No such file or directory - ifconfig
(Errno::ENOENT)
from testara.rb :9:in `mac_address'
from testara.rb:8:in `mac_address'
from testara.rb:23
On linux I get
testara.rb:23: command not found: ifconfig
testara.rb:13:in `mac_address': ifconfig failed (RuntimeError)
from testara.rb:23
···
On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
On Jul 3, 2007, at 12:28 PM, Jeff Barczewski wrote:
>
> Yes, it is not in my user path for gentoo linux either. It is in
> my /sbin
> directory which my non-admin users don't normally have in their path.
>
latest version. can everyone test on various platforms and report
results and/or patch?
>
> Yes, it is not in my user path for gentoo linux either. It is in
> my /sbin
> directory which my non-admin users don't normally have in their path.
>
latest version. can everyone test on various platforms and report
results and/or patch?
cmds.each do |cmd|
stdout = IO.popen('ifconfig'){|fd| fd.readlines}
next unless stdout and stdout.size > 0
lines = stdout and break
end
raise 'ifconfig 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
i promise to post this when we're done so we all have it.
>
> Yes, it is not in my user path for gentoo linux either. It is in
> my /sbin
> directory which my non-admin users don't normally have in their path.
>
latest version. can everyone test on various platforms and report
results and/or patch?
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
Do you really want to keep A-Za-z ??? What about a-f.../oi ?
cmds.each do |cmd|
stdout = IO.popen('ifconfig'){|fd| fd.readlines}
next unless stdout and stdout.size > 0
lines = stdout and break
end
raise 'ifconfig failed' unless lines
candidates = lines.select{|line| line =~ re}
lines.find or lines.detect
raise 'no mac address candidates' unless candidates.first
maddr = candidates.first[re]
raise 'no mac address found' unless maddr @mac_address = maddr.strip
end
i promise to post this when we're done so we all have it.
kind regards.
-a
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama
Robert
···
On 7/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:
On Jul 3, 2007, at 12:28 PM, Jeff Barczewski wrote:
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
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'
lines = nil
cmds.each do |cmd|
stdout = IO.popen('ifconfig'){|fd| fd.readlines} rescue next
next unless stdout and stdout.size > 0
lines = stdout and break
end
raise "#{ cmd } 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
(man i have to get parallels installed...)
-a
···
On Jul 3, 2007, at 1:08 PM, Jeff Barczewski wrote:
On windows I get ifconfig not found exception
testara.rb:9:in `popen': No such file or directory - ifconfig
(Errno::ENOENT)
from testara.rb :9:in `mac_address'
from testara.rb:8:in `mac_address'
from testara.rb:23
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama