Sha256: 5fb954c2b5e39fbd2503b7b840e5e442efa818bf6752786fc28c89d191b88e5f
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 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 rasp2=(/armv7l-linux/ =~ RUBY_PLATFORM) != nil mac=(/darwin/ =~ RUBY_PLATFORM) != nil linux=(/linux/ =~ RUBY_PLATFORM) != nil return get_rasp_id if rasp or rasp2 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.6 | lib/hwid/base.rb |