On 7/3/07, ara.t.howard [email protected] wrote:
will this work on windoze?
lines = nil
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
??
yes, that’s a winner.
works on win xp
works on gentoo linux
On Jul 3, 2007, at 1:13 PM, Tim P. wrote:
Seems to be working on windows (except the annoying “command not
found” messages).
will this work on windoze?
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
#
# ok on windoze?
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
On Jul 3, 2007, at 1:36 PM, Jeff B. 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
On Wed, Jul 04, 2007 at 04:36:47AM +0900, Jeff B. wrote:
On 7/3/07, ara.t.howard [email protected] wrote:
[snip]
cmds.each do |cmd|
raise 'no mac address candidates' unless candidates.first
yes, that’s a winner.
works on win xp
works on gentoo linux
Fwiw, works on FreeBSD, too.
On 7/3/07, ara.t.howard [email protected] wrote:
cmds.each do |cmd|
raise 'no mac address candidates' unless candidates.first
maddr = candidates.first[re]
raise 'no mac address found' unless maddr
@mac_address = maddr.strip
end
This works fine on unmodified FreeBSD 6.2
On Jul 3, 2007, at 12:31 PM, ara.t.howard wrote:
cmds.each do |cmd|
raise 'no mac address candidates' unless candidates.first
maddr = candidates.first[re]
raise 'no mac address found' unless maddr
@mac_address = maddr.strip
end
This one works for me on OSX, Gentoo and windows.
Cheers-
– Ezra Z.
– Lead Rails Evangelist
– [email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)
On Jul 3, 2007, at 3:46 PM, ara.t.howard wrote:
cmds = '/sbin/ifconfig', '/bin/ifconfig', 'ifconfig',
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 B. http://agileconsultingllc.com
[email protected]
On 7/3/07, ara.t.howard [email protected] wrote:
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 ?
candidates = lines.select{|line| line =~ re}
lines.find or lines.detect
-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 Jul 3, 2007, at 2:13 PM, Ezra Z. wrote:
This one works for me on OSX, Gentoo and windows.
okay, here it is
http://drawohara.tumblr.com/post/4862735
if someone breaks it on a reasonable system send a patch and i’ll
update.
thanks everyone for the help!
-a
On 7/3/07, ara.t.howard [email protected] wrote:
update.
Hmm it would help to know what this is for, as Rob pointed out
inactive interfaces might cause problems.
Given the verbose nature of ipconfig /all you will have problems with
hostnames like this
AB-AD-BA…
at least, please, get rid of A-Z in your Regexpression.
Just some thoughts
R
On Jul 3, 2007, at 3:02 PM, Robert D. wrote:
Hmm it would help to know what this is for, as Rob pointed out
inactive interfaces might cause problems.
Given the verbose nature of ipconfig /all you will have problems with
hostnames like this
AB-AD-BA…
at least, please, get rid of A-Z in your Regexpression.
Just some thoughts
http://drawohara.tumblr.com/post/4862735
the current invocation is ok for my purposes: generating a key for
encryption as
“–#{ hostname }–#{ mac_address }–”
but note i added a handle to the complete list to people could monkey
with it if needed.
cheers.
-a