Cross-platform hardware detection
-
On Win I'm using WIN32OLE to get HW info (till now I can get only harddisk datas, I need a good doc reference for WIN32OLE) .....but any cross-platform way to get these infos?
-
what are you trying to get?
there are a number of threads about ipconfig/ifconfig to get the MAC address on both PC and mac...
john
-
I need to get CPU, Network, Harddisk infos
-
Someone else can do the MAC side...
But on a PC...
info =
systeminfo`` [note the left facing `]
Will return the system-info in a text format [a lot of info] - so you'll need to 'parse' it...
It also has an annoying albeit brief black CMD window - you can sidestep this window's appearance by using VB etc...
This requires some convoluted programming...
BUT nothing is perfect...You might be able to add filtering arguments to get exactly what you want...
But... you haven't explained what you want to achieve...
-
On Mac, the nearest is probably system_profiler. It takes a while to run and has only limited options to reduce its large volume of output. Just as TIG suggested for the Windows version, you will no doubt need to invest in some post-processing to extract the specific info you want. Depending on what you need, there might be alternatives.
-
I need to retrieve some alpha-numeric code to locate a pc as unique worldwide, so I thought to get serial numbers (physical) of CPU and/or hardisk and/or MAC address...
-
On a PC you can use
win32ole
to get this kind of info 'silently' [i.e. without the brief cmd window] thus:def get_macaddr() require 'win32ole' macaddr = false net = WIN32OLE.connect("winmgmts;\\\\.") net.InstancesOf("win32_networkadapterconfiguration").each{|i| if i.ipenabled == false #puts "Interface Disabled" else #puts i.ipaddress #puts i.defaultipgateway puts macaddr = i.macaddress end } return macaddr end
This obviously can give you more info than you need, so just take what you want !
I've used#
here to only process the macaddr...
You set a reference for macaddr outside the block and return it after processing - false if failed
On a MAC you can use:
def get_macaddr() return (%x'ipconfig getpacket en1').split('chaddr = ')[1].split("\n")[0] end
Also without any annoying terminal-window !
Simply test for the OS
if RUBY_PLATFORM.downcase =~ /darwin/
it's OSX... -
On a Mac you can use either of these commands to get the MAC address of the default network interface (you will need to parse the line to extract it):
` ifconfig en0 ether
networksetup -getmacaddress en0`
(in both cases that is a zero not an "oh" in en0)
-
Yes... there are many ways...
-
do you know if networksetup -getmacaddress requires "admin" privileges to run.
I asked before [after offering it as an option] in another thread, but never got a definitive answer...
john
-
@driven, good question. Since against all advice I usually keep my account at admin, I sometimes forget to check. The man page for networksetup says it requires admin privileges in general and root for setting most things. ifconfig also requires admin for most settings, but I believe any user can run it to query values.
-
I know variations on
.to_s.split('ether ')[1].strip
have proven robust for a few authors...but my question to all of them is why?
@bomastudio what is your licensing strategy?
you may not need to be so invasive...
john
Advertisement