class Hwid::Base
Attributes
systemid[RW]
Public Instance Methods
get_linux_id()
click to toggle source
# File lib/hwid/base.rb, line 95 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_linuxdebian_id()
click to toggle source
# File lib/hwid/base.rb, line 82 def get_linuxdebian_id res="Serial: unknown" # lshw -quiet -class cpu -disable usb -disable network -disable pci -disable cpuinfo -disable dmi -disable memory -disable isapnp -disable ide -disable device-tree -disable spd | grep -oP '(serial: )\K.* # res=run_cmd("lshw -quiet -class cpu -disable usb -disable network -disable pci -disable cpuinfo -disable dmi -disable memory -disable isapnp -disable ide -disable device-tree -disable spd | grep -oP '(serial: )\\K.*'") res=run_cmd("lshw -quiet -class cpu -class network -disable usb -disable pci -disable cpuinfo -disable dmi -disable memory -disable isapnp -disable ide -disable device-tree -disable spd | grep -oP '(serial: )\\K.*'") res=res.gsub("0000-","") res=res.gsub("\n","") #res=run_cmd("lshw | grep -A 10 '*-cpu' | grep -oP '(serial: )\\K.*'") #puts "Interim result is #{res.inspect}" res=res.chomp puts "debian command result: #{res}" res end
get_mac_id()
click to toggle source
# File lib/hwid/base.rb, line 78 def get_mac_id res=run_cmd('/usr/sbin/system_profiler SPHardwareDataType -timeout 5 | grep Serial') self.parse(res) end
get_platform()
click to toggle source
returns array of platforms
# File lib/hwid/base.rb, line 23 def get_platform platform=[] testos=`uname -a` # puts "osname is #{testos}" platform << "raspberry" if (/arm-linux/ =~ RUBY_PLATFORM) != nil and `uname -a`.include?('armv6') platform << "raspberry" if `uname -a`.include?('armv6') platform << "raspberry 2" if (/armv7l-linux/ =~ RUBY_PLATFORM) != nil and !`uname -a`.include?('armv6') platform << "mac" if (/darwin/ =~ RUBY_PLATFORM) != nil platform << "arm" if (/arm/ =~ RUBY_PLATFORM) != nil platform << "x86" if (/x86/ =~ RUBY_PLATFORM) != nil platform << "i686" if (/i686/ =~ RUBY_PLATFORM) != nil platform << "microsoft" if testos.include?('Microsoft') platform << "debian" if testos.include?('Debian') platform << "ubuntu" if testos.include?('Ubuntu') platform << "linux" if (/linux/ =~ RUBY_PLATFORM) != nil platform end
get_rasp_id()
click to toggle source
# File lib/hwid/base.rb, line 60 def get_rasp_id res=run_cmd('grep Serial /proc/cpuinfo') self.parse(res) end
get_windows_id()
click to toggle source
# File lib/hwid/base.rb, line 64 def get_windows_id puts "running windows linux sigh" res=run_cmd("lshw -quiet -class network -disable usb -disable spd | grep -oP '(serial: )\\K.*'") res=res.gsub("0000-","") res=res.gsub(":","") res=res.gsub("\n","") res=res.gsub(" ","") #res=run_cmd("lshw | grep -A 10 '*-cpu' | grep -oP '(serial: )\\K.*'") #puts "Interim result is #{res.inspect}" res=res.chomp puts "windows command result: #{res}" res end
parse(line)
click to toggle source
parse something like 'Serial : xxxx'
# File lib/hwid/base.rb, line 16 def parse(line) res='unknown' raw=line.split(':') res=raw[1] if raw[1]!=nil res.strip end
platform()
click to toggle source
# File lib/hwid/base.rb, line 13 def platform end
run_cmd(cmd)
click to toggle source
# File lib/hwid/base.rb, line 51 def run_cmd(cmd) res="" begin res=`#{cmd}` rescue Exception => e res="Serial: unknown" end res end