Module: MachineID
- Defined in:
- lib/machineid.rb,
lib/machineid/version.rb
Constant Summary collapse
- VERSION =
'1.0.2'
Class Method Summary collapse
- .bsd? ⇒ Boolean
- .expose?(result) ⇒ Boolean
- .getCommand ⇒ Object
- .getMachineId?(original = false) ⇒ Boolean
- .hash?(guid) ⇒ Boolean
- .host_os ⇒ Object
- .ID?(original = false) ⇒ Boolean
- .linux? ⇒ Boolean
- .mac? ⇒ Boolean
- .unix? ⇒ Boolean
- .windowCmd ⇒ Object
- .windows64? ⇒ Boolean
- .windows? ⇒ Boolean
Class Method Details
.bsd? ⇒ Boolean
14 15 16 |
# File 'lib/machineid.rb', line 14 def bsd? self.host_os =~ /bsd/ end |
.expose?(result) ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/machineid.rb', line 57 def expose?(result) if self.mac? result.split('IOPlatformUUID')[1].split("\n")[0].gsub(/\=|\s+|\"/i, '') elsif self.windows? result.split('REG_SZ')[1].gsub(/\r+|\n+|\s+/i, '') elsif self.linux? result.gsub(/\r+|\n+|\s+/i, '') elsif self.bsd? result.gsub(/\r+|\n+|\s+/i, '') else 'Platform not supported. Please report your platform and architecture in a new Github issue' exit(1) end end |
.getCommand ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/machineid.rb', line 49 def getCommand return 'ioreg -rd1 -c IOPlatformExpertDevice' if self.mac? return self.windowCmd if self.mac? return 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid' if self.bsd? return '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :' if self.linux? end |
.getMachineId?(original = false) ⇒ Boolean
72 73 74 75 76 77 |
# File 'lib/machineid.rb', line 72 def getMachineId?(original = false) cmd = self.getCommand result = self.expose?(`#{cmd}`) return result if original == true self.hash?(result.downcase) end |
.hash?(guid) ⇒ Boolean
39 40 41 |
# File 'lib/machineid.rb', line 39 def hash?(guid) Digest::SHA256.hexdigest(guid) end |
.host_os ⇒ Object
6 7 8 |
# File 'lib/machineid.rb', line 6 def host_os RbConfig::CONFIG['host_os'] end |
.ID?(original = false) ⇒ Boolean
35 36 37 |
# File 'lib/machineid.rb', line 35 def ID?(original = false) self.getMachineId?(original) end |
.linux? ⇒ Boolean
30 31 32 |
# File 'lib/machineid.rb', line 30 def linux? self.host_os =~ /linux|cygwin/ end |
.mac? ⇒ Boolean
22 23 24 |
# File 'lib/machineid.rb', line 22 def mac? self.host_os =~ /mac|darwin/ end |
.unix? ⇒ Boolean
26 27 28 |
# File 'lib/machineid.rb', line 26 def unix? self.host_os =~ /mswin|mingw/ end |
.windowCmd ⇒ Object
43 44 45 46 47 |
# File 'lib/machineid.rb', line 43 def windowCmd cmd = '\\REG.exe QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid' return cmd if self.win64? return "%windir%\\System32#{cmd}" end |
.windows64? ⇒ Boolean
18 19 20 |
# File 'lib/machineid.rb', line 18 def windows64? self.windows? && (/x64/ =~ self.host_os) != nil end |
.windows? ⇒ Boolean
10 11 12 |
# File 'lib/machineid.rb', line 10 def windows? (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil end |