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

    Cross-platform hardware detection

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 4 Posters 831 Views 4 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.
    • bomastudioB Offline
      bomastudio
      last edited by

      On Win I'm using WIN32OLE to get HW info (till now I can get only harddisk datas, I need a good doc reference for WIN32OLE) .....but any cross-platform way to get these infos?

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

        what are you trying to get?

        there are a number of threads about ipconfig/ifconfig to get the MAC address on both PC and mac...

        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
        • bomastudioB Offline
          bomastudio
          last edited by

          I need to get CPU, Network, Harddisk infos

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Someone else can do the MAC side...

            But on a PC...

            info =systeminfo`` [note the left facing `]
            Will return the system-info in a text format [a lot of info] - so you'll need to 'parse' it...
            It also has an annoying albeit brief black CMD window - you can sidestep this window's appearance by using VB etc...
            This requires some convoluted programming...
            BUT nothing is perfect...

            You might be able to add filtering arguments to get exactly what you want...

            But... you haven't explained what you want to achieve...

            TIG

            1 Reply Last reply Reply Quote 0
            • S Offline
              slbaumgartner
              last edited by

              On Mac, the nearest is probably system_profiler. It takes a while to run and has only limited options to reduce its large volume of output. Just as TIG suggested for the Windows version, you will no doubt need to invest in some post-processing to extract the specific info you want. Depending on what you need, there might be alternatives.

              1 Reply Last reply Reply Quote 0
              • bomastudioB Offline
                bomastudio
                last edited by

                I need to retrieve some alpha-numeric code to locate a pc as unique worldwide, so I thought to get serial numbers (physical) of CPU and/or hardisk and/or MAC address...

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  On a PC you can use win32ole to get this kind of info 'silently' [i.e. without the brief cmd window] thus:

                  def get_macaddr()
                    require 'win32ole'
                    macaddr = false
                    net = WIN32OLE.connect("winmgmts;\\\\.")
                    net.InstancesOf("win32_networkadapterconfiguration").each{|i|
                      if i.ipenabled == false
                        #puts "Interface Disabled"
                      else
                        #puts i.ipaddress
                        #puts i.defaultipgateway
                        puts macaddr = i.macaddress
                      end
                    }
                    return macaddr
                  end
                  
                  

                  This obviously can give you more info than you need, so just take what you want !
                  I've used # here to only process the macaddr...
                  You set a reference for macaddr outside the block and return it after processing - false if failed


                  On a MAC you can use:

                  def get_macaddr()
                    return (%x'ipconfig getpacket en1').split('chaddr = ')[1].split("\n")[0]
                  end
                  
                  

                  Also without any annoying terminal-window !


                  Simply test for the OS
                  if RUBY_PLATFORM.downcase =~ /darwin/
                  it's OSX...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    slbaumgartner
                    last edited by

                    On a Mac you can use either of these commands to get the MAC address of the default network interface (you will need to parse the line to extract it):

                    ` ifconfig en0 ether

                    networksetup -getmacaddress en0`

                    (in both cases that is a zero not an "oh" in en0)

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      Yes... there are many ways...

                      TIG

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

                        @steve

                        do you know if networksetup -getmacaddress requires "admin" privileges to run.

                        I asked before [after offering it as an option] in another thread, but never got a definitive answer...

                        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
                        • S Offline
                          slbaumgartner
                          last edited by

                          @driven, good question. Since against all advice I usually keep my account at admin, I sometimes forget to check. The man page for networksetup says it requires admin privileges in general and root for setting most things. ifconfig also requires admin for most settings, but I believe any user can run it to query values.

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

                            I know variations on ifconfig en0 ether.to_s.split('ether ')[1].strip have proven robust for a few authors...

                            but my question to all of them is why?

                            @bomastudio what is your licensing strategy?

                            you may not need to be so invasive...

                            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
                            • 1 / 1
                            • First post
                              Last post
                            Buy SketchPlus
                            Buy SUbD
                            Buy WrapR
                            Buy eBook
                            Buy Modelur
                            Buy Vertex Tools
                            Buy SketchCuisine
                            Buy FormFonts

                            Advertisement