sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Get mac address in ruby

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 2.1k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      biervat
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        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

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

        1 Reply Last reply Reply Quote 0
        • B Offline
          biervat
          last edited by

          Does it work inside sketchup?

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            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

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

            1 Reply Last reply Reply Quote 0
            • B Offline
              biervat
              last edited by

              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'
              
              
              1 Reply Last reply Reply Quote 0
              • D Offline
                driven
                last edited by

                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

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

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MSP_Greg
                  last edited by

                  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

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    biervat
                    last edited by

                    Thanks that works

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement