• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

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.
  • B Offline
    bomastudio
    last edited by 29 Feb 2016, 18:56

    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 29 Feb 2016, 19:47

      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
      • B Offline
        bomastudio
        last edited by 29 Feb 2016, 20:54

        I need to get CPU, Network, Harddisk infos

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 29 Feb 2016, 21:13

          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 29 Feb 2016, 22:23

            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
            • B Offline
              bomastudio
              last edited by 1 Mar 2016, 09:19

              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
              • T Offline
                TIG Moderator
                last edited by 1 Mar 2016, 15:49

                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 1 Mar 2016, 22:15

                  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
                  • T Offline
                    TIG Moderator
                    last edited by 1 Mar 2016, 22:46

                    Yes... there are many ways...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      driven
                      last edited by 1 Mar 2016, 23:01

                      @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 2 Mar 2016, 00:15

                        @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 2 Mar 2016, 01:45

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

                          Advertisement