get mac address in ruby

get mac address in ruby

Postby biervat » Fri Jun 09, 2017 10:39 am

Is it possible to get the mac address in ruby?
I've tried this gem: https://rubygems.org/gems/macaddr but I can't get it working.

I've also tried executing shell commands from within ruby with backticks `getmac` and %x(getmac) but I don't get a response.
0

biervat 
 

Re: get mac address in ruby

Postby driven » Fri Jun 09, 2017 12:50 pm

works on my mac...

you need to fill in your details...

Code: Select all
> Gem.install 'systemu'
[#<Gem::Specification:0x3fdf178087e4 systemu-2.6.5>]
> Gem.install 'macaddr'
[#<Gem::Specification:0x3fdf1841b4c8 macaddr-1.7.1>]
> require 'macaddr'
true
> Mac.addr


john
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: get mac address in ruby

Postby biervat » Fri Jun 09, 2017 12:54 pm

Does it work inside sketchup?
0

biervat 
 

Re: get mac address in ruby

Postby driven » Fri Jun 09, 2017 1:01 pm

that is copy pasted from Ruby Console in SU v17
Code: Select all
# first I installed the two gems
 Gem.install 'systemu'
 Gem.install 'macaddr'
# then I required the gem
require 'macaddr'
# then I called the method
Mac.addr
# I left out the return as I don't want it public...


john
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: get mac address in ruby

Postby biervat » Fri Jun 09, 2017 1:24 pm

It doesn't work in windows 10
I get this error:

Code: Select all
Error: #<NoMethodError: undefined method `pfamily' for nil:NilClass>
C:/Users/maarten/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Gems64/gems/macaddr-1.7.1/lib/macaddr.rb:86:in `block in from_getifaddrs'
C:/Users/maarten/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Gems64/gems/macaddr-1.7.1/lib/macaddr.rb:85:in `select'
C:/Users/maarten/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Gems64/gems/macaddr-1.7.1/lib/macaddr.rb:85:in `from_getifaddrs'
C:/Users/maarten/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Gems64/gems/macaddr-1.7.1/lib/macaddr.rb:62:in `address'
<main>:in `<main>'
SketchUp:1:in `eval'
0

biervat 
 

Re: get mac address in ruby

Postby driven » Fri Jun 09, 2017 6:10 pm

I don't use win dose at all, but you could try fixing the ruby which is failing on line 86...

add this after the current line 85 and save...
Code: Select all
 next if addr.addr.nil?


re-start SU and

Code: Select all
# required the gem
require 'macaddr'
# call the method
Mac.addr


john
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: get mac address in ruby

Postby MSP_Greg » Mon Jun 12, 2017 1:05 am

Over in that other place, there's a thread addressing some similar questions for OSX and Windows.

Re Windows, since Ruby backticks don't work as expected, trying to grab return text from an external command is messy. In the other place, I think Dan posted code using cmd redirection to a file, which will work.

If you want a Windows MAC address and can assume a version of SU with the Ruby std-lib included, I posted a WIN32OLE example here
0

MSP_Greg 
 

Re: get mac address in ruby

Postby biervat » Thu Jun 15, 2017 7:52 am

Thanks that works
0

biervat 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 4 guests

Visit our sponsors: