Class: Hwid::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hwid/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#systemidObject

Returns the value of attribute systemid.



8
9
10
# File 'lib/hwid/base.rb', line 8

def systemid
  @systemid
end

Instance Method Details

#get_linux_idObject



45
46
47
48
49
50
# File 'lib/hwid/base.rb', line 45

def get_linux_id
  res="Serial: unknown"
  ifconfig_avail = !(ifconfig_path = `which ifconfig`.strip).empty? && File.executable?(ifconfig_path)
  res=run_cmd('ifconfig | grep HWaddr').split.last if ifconfig_avail
  res
end

#get_mac_idObject



41
42
43
44
# File 'lib/hwid/base.rb', line 41

def get_mac_id
  res=run_cmd('/usr/sbin/system_profiler SPHardwareDataType -timeout 0 | grep Serial')
  self.parse(res)
end

#get_rasp_idObject



37
38
39
40
# File 'lib/hwid/base.rb', line 37

def get_rasp_id
  res=run_cmd('grep Serial  /proc/cpuinfo')
  self.parse(res)
end

#parse(line) ⇒ Object

parse something like ‘Serial : xxxx’



13
14
15
16
17
18
# File 'lib/hwid/base.rb', line 13

def parse(line)
  res='unknown'
  raw=line.split(':')
  res=raw[1] if raw[1]!=nil
  res.strip
end

#platformObject



10
11
# File 'lib/hwid/base.rb', line 10

def platform
end

#run_cmd(cmd) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/hwid/base.rb', line 28

def run_cmd(cmd)
  res=""
  begin
    res=`#{cmd}`
  rescue Exception => e
    res="Serial: unknown"
  end
  res
end