Getting unique ID of a user's machine

I tend to request the minimum from system_profiler and clean it further in ruby…

# this will quickly return all MAC Address's
en_all = `system_profiler SPNetworkDataType | grep 'MAC'`
# then use a regular expression to clean up
ary = en_all.chomp!.gsub("\n", ',').gsub(/\s+(Hardware)* \(*MAC\)* Address: /, '').split(',')

john

Hello,
Checking my new knowledge. I expect the below command returns the report I’ve built from the above link.
command

str_report = `system_profiler SPHardwareDataType SPParallelATADataType SPEthernetDataType SPDisplaysDataType SPMemoryDataType`

copy-paste re-built report

Hardware:

    Hardware Overview:

        Model Name: iMac
        Model Identifier: iMacAA,B
        Processor Name: Intel Core i7
        Processor Speed: 2.8 GHz
        Number of Processors: 1
        Total Number of Cores: 4
        L2 Cache (per Core): 256 KB
        L3 Cache: 8 MB
        Memory: 16 GB
        Processor Interconnect Speed: 4.8 GT/s
        Boot ROM Version: XXXXX.YYYYY.ZZZ
        SMC Version (system): X.YZYZYZY
        Serial Number (system): OOOOOOOOOOOOO
        Hardware UUID: XXXXXXX-YYYYYYY-ZZZZZZZZZZZZZZZZZZZZ
ATA:

    ATA Bus:

        ST9808210A:

          Capacity: 74.53 GB
          Model: ST9808210A
          Revision: 3.04
          Serial Number: 3LF17HVC
          Removable Media: No
          Detachable Drive: No
          BSD Name: disk0
          Protocol: ATA
          Unit Number: 0
          Socket Type: Internal
          OS9 Drivers: No
          S.M.A.R.T. status: Verified
          Volumes:
            Macintosh HD:
              Capacity: 74.41 GB
              Available: 50.08 GB
              Writable: Yes
              File System: Journaled HFS+
              BSD Name: disk0s3
              Mount Point: /
          Volumes:
            disk0s3:
              Capacity: 74.41 GB
              Available: 50.08 GB
              Writable: Yes
              File System: Journaled HFS+

        MATSHITACD-RW  CW-8124:

          Model: MATSHITACD-RW  CW-8124
          Revision: DACD
          Serial Number:
          Detachable Drive: No
          Protocol: ATAPI
          Unit Number: 1
          Socket Type: Internal
Ethernet Cards:

    USB Ethernet Adapter - AX88772A:

      Type: USB
      BSD name: en5
      Kext name: AppleUSBEthernet.kext
      Location: /System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleUSBEthernet.kext
      Version: 2.4.13
      MAC Address: 00:0e:c6:f9:23:0b
      Product ID: 30506
      Vendor ID: 2965
Graphics/Displays:

    ATI Radeon 9200:

      Chipset Model: ATY,RV280
      Type: Display
      Bus: AGP
      VRAM (Total): 32 MB
      Vendor: ATI (0x1002)
      Device ID: 0x5962
      Revision ID: 0x0001
      ROM Revision: 113-xxxxx-120
      Displays:
        RDT1711S:
          Resolution: 1280 x 1024 @ 60 Hz
          Depth: 32-bit Color
          Core Image: Not Supported
          Main Display: Yes
          Mirror: Off
          Online: Yes
          Quartz Extreme: Supported
          Rotation: Supported
Memory:

    DIMM0/J11:

      Size: 512 MB
      Type: DDR SDRAM
      Speed: PC3200U-30330
      Status: OK

Am I right - SPEthernetDataType is meant to return eth[0] only - ?
if so how much time does the command take?

flt_start_time = Time.new().to_f
str_report = `system_profiler SPHardwareDataType SPParallelATADataType SPEthernetDataType SPDisplaysDataType SPMemoryDataType`
flt_end_time = Time.new().to_f
int_elapsed_time = ((flt_end_time - flt_end_time)*1000).to_i
str_out = "with system_profiler report\n  elapsed time  " +
	int_elapsed_time.to_s + "\n  str.len " + str_report.length.to_s +
	"\n  ary.len " + str_report.split("\n").length.to_s + "\nend with"
puts str_out

Have a good week-end
WhyDi

yes, but without any unique identifier…

after modifying int_elapsed_time = (flt_end_time - flt_start_time).round(3).to_s + ' seconds'

your code returns

with system_profiler report
  elapsed time  1.221285 seconds
  str.len 2411
  ary.len 101
end with

with a targeted approach to get unique information using grep with the -e flag…

flt_start_time = Time.new().to_f
str_report = `system_profiler SPNetworkDataType SPHardwareDataType | 
grep -e 'MAC' -e 'Serial Number (system)' -e 'Hardware UUID:'`
flt_end_time = Time.new().to_f
int_elapsed_time = (flt_end_time - flt_start_time).round(3).to_s + ' seconds'
str_out = "with system_profiler report\n  elapsed time  " +
	int_elapsed_time + "\n  str.len " + str_report.length.to_s +
	"\n  ary.len " + str_report.split("\n").length.to_s + "\nend with"
puts str_out

with system_profiler report
  elapsed time  0.592 seconds
  str.len 229
  ary.len 5
end with

and the concise output looks like this… [modified results for privacy]

          MAC Address: 00:1x:x1:11:11:11
          MAC Address: 00:2x:2x:xx:xx:2x:xx:22
          MAC Address: 00:3x:x3:x3:33:xx
      Serial Number (system): W12345X6XXX
      Hardware UUID: 00000000-0000-1000-1000-001XX1111111

john

OSX as slow as Windows!

get lost! what does -e flag stand for?

do each Mac have at least ethernet[0] filled?

WhyDi

     -e pattern, --regexp=pattern
             Specify a pattern used during the search of the input: an input
             line is selected if it matches any of the specified patterns.
             This option is most useful when multiple -e options are used to
             specify multiple patterns, or when a pattern begins with a dash
             (`-').

there are now many mac’s without an ethernet port, maybe @slbaumgartner knows if it’s used internally…

my strategy would be to store 4 or 5 items, but subsequently run as licensed if 2 or more get matched…

john

Hello,
I like your strategy. Perhaps adding HDD serial number…
waiting for @slbaumgartner

I’ve got grep manual. so smart grep but too much at the time!

What do you think about ioreg replacing system_profiler? lower level, quicker.
from the web…
https://www.mikemackintosh.com/quickest-way-to-query-mac-serial-numbers/

ioreg -rd1 -c IOPlatformExpertDevice | grep -E '(UUID)'
ioreg -l | grep IOMACAddress
ioreg -l | grep IOPlatformSerialNumber | awk '{print $4}'

can we compact several commands on one line as system_profiler does?

WhyDi

Starting a few years ago, Apple stopped putting a separate Ethernet RJ-45 port onto many models and instead required an adapter plugged into either a Thunderbolt or USB-C port. On my MacBook Pro, the Thunderbolt Ethernet shows up in the system_profiler output, but it does not have a MAC address unless the adapter is attached to the mac (it doesn’t have to be connected to an actual ethernet, just attached to the mac). In contrast, the Wi-Fi always has a MAC address, even if Wi-Fi is turned off.

I don’t know about every Mac model, but I suspect this behavior is the same.

Steve and John thanks for your time this Sunday. I appreciate.

Regarding MacAddress
All this making John strategy the only available. Good news is I know ‘what’. One less thing to worry. Bad news is far more work and I no longer see my next week-end off! but your willingness is worth.

I hope ioreg able to save some second tenth and elegantly get UUID and CPU and HDD and SYSTEM serial numbers even step by step.

WhyDi

I haven’t really keep up with this thread, but I recall seeing wmic, shell redirection, MAC Address, Drive SerialNumber, etc. Old code, revised a bit for this, only tested on Win7 & SU2017.

Maybe Win32Ole? If that’s okay, try the following:

# load '<path to this>'

require 'win32ole'

locator = WIN32OLE.new("WbemScripting.SWbemLocator")
wmi = locator.ConnectServer(".", "/root/cimv2")

adapters = wmi.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
drives   = wmi.ExecQuery("Select * from Win32_DiskDrive")

ctr = 0 ; item0 = nil


puts "\n#{'-' * 20} Adapter Info"
adapters.each { |net|
  if net.MACAddress
    item0 = net if ctr == 0 ; ctr += 1
    puts "#{net.MACAddress} #{net.IPEnabled.to_s.ljust(6)} #{(net.IPAddress || []).join('  ')}"
  end
}

if item0
  puts "\n#{'-' * 20} Adapter Properties"
  item0.properties_.each { |prop| puts prop.Name }
end

ctr = 0 ; item0 = nil

puts "\n#{'-' * 20} Drive Info"
drives.each { |drv|
  if drv.SerialNumber
    item0 = drv if ctr == 0 ; ctr += 1
    puts "#{drv.SerialNumber.strip.ljust(20)}  #{drv.Description.ljust(20)} #{drv.InterfaceType}"
  end
}

if item0
  puts "\n#{'-' * 20} Drive Properties"
  item0.properties_.each { |prop| puts prop.Name }
end

Hello,

Great MSP_Greg! it works fine SketchUp 17, 16, 15 and 14. no black window shown.

As far as I remember @DanRathbun made a paper about installing win32ole on SketchUp08 and SketchUp13 but I’m no longer able to find the link. Backward compatibility require such install.
Does anyone remember or explain how to install.
[EDIT] I’ve got the link
Win32API and Win32OLE so files

[EDIT] here is @MSP_Greg script on Windows Intel Pentium 2.50GHZ. Mind the two first sub-lines about elapsed time. Mainly the first one related to CPU data.

start version ------------------------------------------------2.2.4
with WindowsManagementInstrumentation, select from key
    elapsed time CPU only : 2.094 seconds - below Win32_Processor only!
   elapsed time remaining : 0.359 seconds
 with Win32_Processor
                     Name : AMDel(notR) Pentron(notR) CPU Z999 @ 2500GHz
              ProcessorId : 0123456789ABCDEF
 end with
 with Win32_BIOS
             SerialNumber : SNEU0123456789ABCDEF00
 end with
 with Win32_ComputerSystemProduct
                     UUID : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
 end with
 with Win32_VideoController
                     Name : NVIATI noForce lessThan0
           VideoProcessor : lessThan0
 end with
 with Win32_PhysicalMemory
                 Capacity : 17179869184
                 Capacity : 17179869184
 end with
 with Win32_PhysicalMedia
             SerialNumber : 2032111222333444
                      Tag : \\.\PHYSICALDRIVE1
             SerialNumber :      ZZ-QWERTYC012345
                      Tag : \\.\PHYSICALDRIVE0
             SerialNumber : 
                      Tag : \\.\CDROM0
 end with
end with
---------------------------------------------------------------end

have a good week
WhyDi

Hello,
back to Mac OSX. May you run the following script telling us about detailed elapsed times.

indent = "  "
str_out = "with system_profiler\n"
flt_start_time = Time.new().to_f
flt_keep_start_time = flt_start_time
str_report = `system_profiler SPHardwareDataType`
flt_end_time = Time.new().to_f
flt_elapsed_time = (flt_end_time - flt_start_time).round(3)
str_out += indent + "with SPHardwareDataType\n"+
	indent + indent + "elapsed time " + flt_elapsed_time.to_s + " seconds\n" +
	indent + indent + "str.len " + str_report.length.to_s + "\n" +
	indent + indent + "ary.len " + str_report.split("\n").length.to_s + "\n" +
	indent + "end with\n"

flt_start_time = Time.new().to_f
str_report = `system_profiler SPDisplaysDataType`
flt_end_time = Time.new().to_f
flt_elapsed_time = (flt_end_time - flt_start_time).round(3)
str_out += indent + "with SPDisplaysDataType\n"+
	indent + indent + "elapsed time " + flt_elapsed_time.to_s + " seconds\n" +
	indent + indent + "str.len " + str_report.length.to_s + "\n" +
	indent + indent + "ary.len " + str_report.split("\n").length.to_s + "\n" +
	indent + "end with\n"

flt_start_time = Time.new().to_f
str_report = `system_profiler SPNetworkDataType`
flt_end_time = Time.new().to_f
flt_elapsed_time = (flt_end_time - flt_start_time).round(3)
str_out += indent + "with SPNetworkDataType\n"+
	indent + indent + "elapsed time " + flt_elapsed_time.to_s + " seconds\n" +
	indent + indent + "str.len " + str_report.length.to_s + "\n" +
	indent + indent + "ary.len " + str_report.split("\n").length.to_s + "\n" +
	indent + "end with\n"

flt_start_time = Time.new().to_f
str_report = `system_profiler SPParallelATADataType`
flt_end_time = Time.new().to_f
flt_elapsed_time = (flt_end_time - flt_start_time).round(3)
str_out += indent + "with SPParallelATADataType\n"+
	indent + indent + "elapsed time " + flt_elapsed_time.to_s + " seconds\n" +
	indent + indent + "str.len " + str_report.length.to_s + "\n" +
	indent + indent + "ary.len " + str_report.split("\n").length.to_s + "\n" +
	indent + "end with\n"

flt_end_time = Time.new().to_f
flt_elapsed_time = (flt_end_time - flt_keep_start_time).round(3)
str_out += indent + "full elapsed time " + flt_elapsed_time.to_s + " seconds\n" +
	"end with"
puts str_out

Thanks in advance
WhyDi

with system_profiler
  with SPHardwareDataType
    elapsed time 0.497 seconds
    str.len 460
    ary.len 17
  end with
  with SPDisplaysDataType
    elapsed time 0.402 seconds
    str.len 557
    ary.len 23
  end with
  with SPNetworkDataType
    elapsed time 0.34 seconds
    str.len 2622
    ary.len 94
  end with
  with SPParallelATADataType
    elapsed time 0.342 seconds
    str.len 314
    ary.len 14
  end with
  full elapsed time 1.583 seconds
end with

like this?

john

Hello,
oh yes! like this. Quite acceptable.

digressing a bit
I’m after a way of loading system default client-mail from Ruby with backward compatibility down to SketchUp 8 and cross-platform of course.
I would like to avoid html code. so right from Ruby code.
Maybe I’d better opening a new thread?

WhyDi

a new thread is a good idea and maybe add some more details of what your trying to do…

you will have issues finding the right code for 4 versions of ruby on 2 platforms…

john

Too much! I agree with with you
cross-platform Html mailto: should easily feel our need.
Just one dialog more to build. not so hard at all.
see you soon

Hello,
may you run the following command on the mac

and tell me what’s the output? does it work?
any way to do with system_profiler?
Have a good day
WhyDi

then something about system_profiler
on beta-tester computers I got the following from command

`system_profiler SPHardwareDataType`
Hardware:

    Hardware Overview:

      Model Name: Mac xxx
      Model Identifier: MacProx,x
      Processor Name: xxxx-Core Intel xxxx
      Processor Speed: x,xx GHz
      Number of Processors: x
      Total Number of Cores: x
      L2 Cache (per Core): xxx KB
      L3 Cache: x MB
      Memory: x GB
      Processor Interconnect Speed: x.x GT/s
      Boot ROM Version: xxxx.xxxx.xxxx
      SMC Version (system): x.xxxx
      SMC Version (processor tray): x.xxxx
      Serial Number (system): FFFFFFFFFFF
      Serial Number (processor tray): FFFFFFFFFFFFF
      Hardware UUID: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF

may you check lines that do not match on your own computer please?
as you may guess it’s all about (processor tray) and UUID, of course!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.