Heesob Park <phasis@gmail.com> writes:
> 2009/1/11 Matt Harrison <iwasinnamuknow@genestate.com>:
>> Daniel Berger wrote:
>>>
>>> On Jan 10, 4:04 pm, Jarmo Pertman <jarm...@gmail.com> wrote:
>>>>
>>>> puts RUBY_PLATFORM
>>>>
>>>> Fernando Malard wrote:
>>>>>
>>>>> Hello,
>>>>> How can I unique identify the OS where my Ruby code is running?
>>>>> I can do this using specific Win32 features but I looking for an OS
>>>>> independent approach...maybe using the HD serial?
>>>>> Regards,
>>>>> Fernando.
>>>
>>> No, don't use RUBY_PLATFORM because it won't work with JRuby, and
>>> possibly other implementations.
>>>
>>> Instead, require "rbconfig", then check Config::CONFIG['host_os'].
>>>
>>> Regards,
>>>
>>> Dan
>>>
>>
>> I believe the OP wants to get a unique identifier for each host, something
>> like a GUID. I have no idea how you would make this cross platform though,
>> maybe IP address but those change, or HD serial, but again that's
>> changable...
HD move from one computer to the other. The OP asked for a computer
ID, not a HD ID. The IP addresses identify interfaces. There may be
several or no interface per computer. Which IP address would you use?
Nowadays, most users are behind a NAT with private IP, so this won't
identify anything.
>> Windows supports GUIDs inherantly however AFAIK *nix systems don't.
>>
>> Sorry I don't have a solution.
>>
>> Matt
>>
>>
> If the OP wants the unique ID per computer in cross platform way, the
> mac address is one solution.
Network cards move from computer to the other. Network cards break
down and are changed. MAC addresses are not always stored in ROM,
some cards allow changing the MAC address. And a computer has several
MAC addresses (even if with only one ethernet address, MAC addresses
are also used on Wifi and Firewire).
It's a problem of definition. What do you consider the computer? Is
that the CPU? Is that an installation of the system? Is that some
given configuration of hardware?
If Internet connectivity is assumed, I would propose a server issuing
unique IDs, and a procedure to mark an "OS" like the OP names it,
which would fetch a new unique ID from the server and store it in some
global file. Then the ID would be retrieved from this global file
named for example, /etc/com.gmail.fpmalard.unique-id on unix systems
and something else on the other systems.
If Internet connectivity cannot be assumed, then you would have to
build a unique ID trying to gather specific data and random data to
reduce the probabilities of a collision. There are several web pages
indicating how to build such an ID. The point is that the specific
data about the computer is gathered only when the ID is made, not when
it's used. If you change your hardware configuration, or move your
"OS" to some other hardware, you should be able to keep your ID.
--
__Pascal Bourguignon__