Get mac address in ruby
-
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. -
works on my mac...
you need to fill in your details...
> 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
-
Does it work inside sketchup?
-
that is copy pasted from Ruby Console in SU v17
# 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
-
It doesn't work in windows 10
I get this error: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'
-
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...
next if addr.addr.nil?
re-start SU and
# required the gem require 'macaddr' # call the method Mac.addr
john
-
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
-
Thanks that works
Advertisement