class Sys::Uname
def self.architecture
system, e.g. sparc, i386, etc.
The basic instruction set architecture of the current
def self.architecture uname.architecture end
def self.architecture(cpu_num = 0, host = Socket.gethostname)
Returns the CPU architecture, e.g. "x86"
def self.architecture(cpu_num = 0, host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else case wmi.Architecture when 0 'x86' when 1 'mips' when 2 'alpha' when 3 'powerpc' when 6 'ia64' when 9 'x86_64' else 'unknown' end end end
def self.convert(str)
String rather than a Fixnum/Bignum. This deals with that for now.
There is a bug in win32ole where uint64 types are returned as a
def self.convert(str) return nil if str.nil? # Don't turn nil into 0 str.to_i end
def self.dhcp_cache
from the server.
of the interface configured by boot(1M) followed by the DHCPACK reply
The string consisting of the ASCII hexidecimal encoding of the name
def self.dhcp_cache uname.dhcp_cache end
def self.get_model
Returns the model for systems that define sysctl().
def self.get_model buf = 0.chr * BUFSIZE mib = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_HW, HW_MODEL]) size = FFI::MemoryPointer.new(:long, 1).write_int(buf.size) sysctl(mib, 2, buf, size, nil, 0) buf.strip end
def self.hw_provider
The name of the of the hardware provider.
def self.hw_provider uname.hw_provider end
def self.hw_serial
of the physical machine on which the function is executed.
The ASCII representation of the hardware-specific serial number
def self.hw_serial uname.hw_serial.to_i end
def self.isa_list
current system.
The variant instruction set architectures executable on the
def self.isa_list uname.isa_list end
def self.machine
Uname.machine # => 'i686'
Example:
Returns the machine hardware type.
def self.machine uname.machine end
def self.machine(cpu_num = 0, host = Socket.gethostname)
appears that MS doesn't necessarily patch this, either.
were unknown to the OS when the OS was originally released. It
This may or may not return the expected value because some CPU types
--
Returns the machine hardware type. e.g. "i686".
def self.machine(cpu_num = 0, host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else # Convert a family number into the equivalent string case wmi.Family when 1 'Other' when 3 '8086' when 4 '80286' when 5 '80386' when 6 '80486' when 7 '8087' when 8 '80287' when 9 '80387' when 10 '80487' when 11 'Pentium brand' when 12 'Pentium Pro' when 13 'Pentium II' when 14 'Pentium processor with MMX technology' when 15 'Celeron' when 16 'Pentium II Xeon' when 17 'Pentium III' when 18 'M1 Family' when 19 'M2 Family' when 24 'K5 Family' when 25 'K6 Family' when 26 'K6-2' when 27 'K6-3' when 28 'AMD Athlon Processor Family' when 29 'AMD Duron Processor' when 30 'AMD2900 Family' when 31 'K6-2+' when 32 'Power PC Family' when 33 'Power PC 601' when 34 'Power PC 603' when 35 'Power PC 603+' when 36 'Power PC 604' when 37 'Power PC 620' when 38 'Power PC X704' when 39 'Power PC 750' when 48 'Alpha Family' when 49 'Alpha 21064' when 50 'Alpha 21066' when 51 'Alpha 21164' when 52 'Alpha 21164PC' when 53 'Alpha 21164a' when 54 'Alpha 21264' when 55 'Alpha 21364' when 64 'MIPS Family' when 65 'MIPS R4000' when 66 'MIPS R4200' when 67 'MIPS R4400' when 68 'MIPS R4600' when 69 'MIPS R10000' when 80 'SPARC Family' when 81 'SuperSPARC' when 82 'microSPARC II' when 83 'microSPARC IIep' when 84 'UltraSPARC' when 85 'UltraSPARC II' when 86 'UltraSPARC IIi' when 87 'UltraSPARC III' when 88 'UltraSPARC IIIi' when 96 '68040' when 97 '68xxx Family' when 98 '68000' when 99 '68010' when 100 '68020' when 101 '68030' when 112 'Hobbit Family' when 120 'Crusoe TM5000 Family' when 121 'Crusoe TM3000 Family' when 122 'Efficeon TM8000 Family' when 128 'Weitek' when 130 'Itanium Processor' when 131 'AMD Athlon 64 Processor Family' when 132 'AMD Opteron Processor Family' when 144 'PA-RISC Family' when 145 'PA-RISC 8500' when 146 'PA-RISC 8000' when 147 'PA-RISC 7300LC' when 148 'PA-RISC 7200' when 149 'PA-RISC 7100LC' when 150 'PA-RISC 7100' when 160 'V30 Family' when 176 'Pentium III Xeon' when 177 'Pentium III Processor with Intel SpeedStep Technology' when 178 'Pentium 4' when 179 'Intel Xeon' when 180 'AS400 Family' when 181 'Intel Xeon processor MP' when 182 'AMD AthlonXP Family' when 183 'AMD AthlonMP Family' when 184 'Intel Itanium 2' when 185 'AMD Opteron Family' when 190 'K7' when 198 'Intel Core i7-2760QM' when 200 'IBM390 Family' when 201 'G4' when 202 'G5' when 203 'G6' when 204 'z/Architecture Base' when 250 'i860' when 251 'i960' when 260 'SH-3' when 261 'SH-4' when 280 'ARM' when 281 'StrongARM' when 300 '6x86' when 301 'MediaGX' when 302 'MII' when 320 'WinChip' when 350 'DSP' when 500 'Video Processor' else 'Unknown' end end end
def self.model
Uname.model # => 'MacBookPro5,3'
Example:
Returns the model type.
def self.model uname.model end
def self.nodename
Uname.nodename # => 'your_host.foo.com'
Example:
necessarily, the same as the host name.
which this node is attached, if any. This is often, but not
Returns the name of this node within the communications network to
def self.nodename uname.nodename end
def self.nodename(host = Socket.gethostname)
same as the system's hostname.
Returns the nodename. This is usually, but not necessarily, the
def self.nodename(host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0).CSName end end
def self.parse_ms_date(str)
Ruby Time object.
Converts a string in the format '20040703074625.015625-360' into a
def self.parse_ms_date(str) return if str.nil? Time.parse(str.split('.')[0]) end
def self.platform
The specific model of the hardware platform, e.g Sun-Blade-1500, etc.
def self.platform uname.platform end
def self.release
Uname.release # => '2.2.16-3'
Example:
Returns the current release level of your operating system.
def self.release uname.release end
def self.release(host = Socket.gethostname)
Returns the release number, e.g. 5.1.2600.
def self.release(host = Socket.gethostname) cs = "winmgmts://#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0).Version end end
def self.srpc_domain
The Secure Remote Procedure Call domain name.
def self.srpc_domain uname.srpc_domain end
def self.sysname
Uname.sysname # => 'Darwin'
Example:
Returns the name of this implementation of the operating system.
def self.sysname uname.sysname end
def self.sysname(host = Socket.gethostname)
Returns the operating system name, e.g. "Microsoft Windows XP Home"
def self.sysname(host = Socket.gethostname) cs = 'winmgmts:{impersonationLevel=impersonate,(security)}' cs += "//#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0).Caption.strip end end
def self.uname
p Sys::Uname.uname
require 'sys/uname'
Example:
On HP-UX, it will also include the id_number.
On OS X and BSD platforms it will also include the model.
and release of your system.
Returns a struct that contains the sysname, nodename, machine, version
def self.uname utsname = UnameFFIStruct.new raise Error, 'uname() function call failed' if uname_c(utsname) < 0 struct = UnameStruct.new struct[:sysname] = utsname[:sysname].to_s struct[:nodename] = utsname[:nodename].to_s struct[:release] = utsname[:release].to_s struct[:version] = utsname[:version].to_s struct[:machine] = utsname[:machine].to_s struct[:model] = get_model() if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i struct[:id_number] = utsname[:__id_number].to_s if RbConfig::CONFIG['host_os'] =~ /hpux/i struct[:domainname] = utsname[:domainname].to_s if RbConfig::CONFIG['host_os'] =~ /linux/i # Let's add a members method that works for testing and compatibility if struct.members.nil? struct.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def members @table.keys.map(&:to_s) end RUBY end struct.freeze end
def self.uname(host = Socket.gethostname)
Please see the MSDN documentation for what each of these fields mean.
machine, version, and release, as well as a plethora of other fields.
Returns a struct of type UnameStruct that contains sysname, nodename,
def self.uname(host = Socket.gethostname) cs = "winmgmts://#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else os = wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0) UnameStruct.new( os.BootDevice, os.BuildNumber, os.BuildType, os.Caption, os.CodeSet, os.CountryCode, os.CreationClassName, os.CSCreationClassName, os.CSDVersion, os.CSName, os.CurrentTimeZone, os.Debug, os.Description, os.Distributed, os.EncryptionLevel, os.ForegroundApplicationBoost, convert(os.FreePhysicalMemory), convert(os.FreeSpaceInPagingFiles), convert(os.FreeVirtualMemory), parse_ms_date(os.InstallDate), parse_ms_date(os.LastBootUpTime), parse_ms_date(os.LocalDateTime), os.Locale, os.Manufacturer, os.MaxNumberOfProcesses, convert(os.MaxProcessMemorySize), os.Name, os.NumberOfLicensedUsers, os.NumberOfProcesses, os.NumberOfUsers, os.Organization, os.OSLanguage, os.OSProductSuite, os.OSType, os.OtherTypeDescription, os.PlusProductID, os.PlusVersionNumber, os.Primary, os.ProductType, os.respond_to?(:QuantumLength) ? os.QuantumLength : nil, os.respond_to?(:QuantumType) ? os.QuantumType : nil, os.RegisteredUser, os.SerialNumber, os.ServicePackMajorVersion, os.ServicePackMinorVersion, convert(os.SizeStoredInPagingFiles), os.Status, os.SuiteMask, os.SystemDevice, os.SystemDirectory, os.SystemDrive, convert(os.TotalSwapSpaceSize), convert(os.TotalVirtualMemorySize), convert(os.TotalVisibleMemorySize), os.Version, os.WindowsDirectory ) end end
def self.version
Uname.version # => '5.9'
Example:
Returns the current version level of your operating system.
def self.version uname.version end
def self.version(host = Socket.gethostname)
including it as part of the connection.
the 'InstancesOf' method to get the data we need, rather than
The instance name is unpredictable, so we have to resort to using
--
separated by a hyphen, e.g. "2915-Service Pack 2".
Returns the version plus patch information of the operating system,
def self.version(host = Socket.gethostname) cs = "winmgmts://#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => err raise Error, err else ole = wmi.InstancesOf('Win32_OperatingSystem').ItemIndex(0) str = "#{ole.Version} #{ole.BuildNumber}-" "#{str}#{ole.ServicePackMajorVersion}" end end