Sha256: 2c33a76732be9ff6077494a00b4e165b1b822bb36171cae6073f781668c24988
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
require 'rubygems' module Hwid def self.systemid Hwid::Base.new.systemid end class Base attr_accessor :systemid def platform end #parse something like 'Serial : xxxx' def parse(line) res='unknown' raw=line.split(':') res=raw[1] if raw[1]!=nil res.strip end def systemid rasp=(/arm-linux/ =~ RUBY_PLATFORM) != nil mac=(/darwin/ =~ RUBY_PLATFORM) != nil linux=(/linux/ =~ RUBY_PLATFORM) != nil return get_rasp_id if rasp return get_mac_id if mac return get_linux_id if linux end def run_cmd(cmd) res="" begin res=`#{cmd}` rescue Exception => e res="Serial: unknown" end res end def get_rasp_id res=run_cmd('grep Serial /proc/cpuinfo') self.parse(res) end def get_mac_id res=run_cmd('/usr/sbin/system_profiler SPHardwareDataType -timeout 0 | grep Serial') self.parse(res) end 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 end # Class end #Module
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hwid-0.1.5 | lib/hwid/base.rb |