Class: Hwid::Base
- Inherits:
-
Object
- Object
- Hwid::Base
- Defined in:
- lib/hwid/base.rb
Instance Attribute Summary collapse
-
#systemid ⇒ Object
Returns the value of attribute systemid.
Instance Method Summary collapse
- #get_linux_id ⇒ Object
- #get_mac_id ⇒ Object
- #get_rasp_id ⇒ Object
-
#parse(line) ⇒ Object
parse something like ‘Serial : xxxx’.
- #platform ⇒ Object
- #run_cmd(cmd) ⇒ Object
Instance Attribute Details
#systemid ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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 |
#platform ⇒ Object
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 |