Forum: Ruby Unique identify computer (both Windows and MacOSX)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fernando M. (Guest)
on 2009-01-09 18:53
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.
Jarmo P. (Guest)
on 2009-01-11 01:05
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.
Daniel B. (Guest)
on 2009-01-11 05:18
(Received via mailing list)
On Jan 10, 4:04 pm, Jarmo P. <removed_email_address@domain.invalid> wrote:
> > 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
Matt H. (Guest)
on 2009-01-11 06:06
(Received via mailing list)
Daniel B. wrote:
>>> 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...

Windows supports GUIDs inherantly however AFAIK *nix systems don't.

Sorry I don't have a solution.

Matt
Heesob P. (Guest)
on 2009-01-11 06:46
(Received via mailing list)
2009/1/11 Matt H. <removed_email_address@domain.invalid>:
>>>> I can do this using specific Win32 features but I looking for an OS
>>
> 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.

Try ruby -r macaddr -e'  p Mac.addr  '

gem install macaddr

Regards,

Park H.
Pascal J. Bourguignon (Guest)
on 2009-01-12 11:36
(Received via mailing list)
Heesob P. <removed_email_address@domain.invalid> writes:

>>>>> How can I unique identify the OS where my Ruby code is running?
>>> 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.
Fernando M. (Guest)
on 2009-01-12 12:37
Hello,

First, thank you all for your comments.
In fact the idea is to generate a install ID of my application to use
some kind of a registration system. The user will send me an INSTALL ID
plus a SERIAL and I will return an AUTHORIZATION key.

Most of MS Windows applications get the GUID (UUID) number from the
installed system which is unique from machine to machine. Some combine
this number with HD serial, BIOS identification, etc.

Of course it is almost impossible to build a 100% secure registration
system and as you all said the hardware can be moved from machine to
machine.

My idea is to generate this unique ID from HD serial, mac address and OS
identification(a combination of all these).

Another approach I'm thinking about is to create a platform dependent
executable module which can be called from inside Ruby script and return
the machine GUID. This way for Windows I can create an EXE module, for
Mac I can create an EXEC module and so on.

Any ideas?

Regards,
Fernando.

Pascal J. Bourguignon wrote:
> Heesob P. <removed_email_address@domain.invalid> writes:
>
>>>>>> How can I unique identify the OS where my Ruby code is running?
>>>> 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.
Brian C. (Guest)
on 2009-01-13 11:14
Pascal J. Bourguignon wrote:
> 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.

There is a uuid gem too.

> 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.

But if you store it on the hard drive, then the uid moves with the hard
drive. If you backup and restore to another machine, then you will have
two machines with the same uid.
Pascal J. Bourguignon (Guest)
on 2009-01-13 11:50
(Received via mailing list)
Brian C. <removed_email_address@domain.invalid> writes:

>> 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.
>
> But if you store it on the hard drive, then the uid moves with the hard
> drive. If you backup and restore to another machine, then you will have
> two machines with the same uid.

Yes, exactly.  Why would you want to forbid the user to do that. After
all, it's him who pays for that software, no?
Fernando M. (Guest)
on 2009-01-13 12:47
Hello,

I think the mac address is acceptable because major of NIC cards today
are onboard and the computer board is the component that has less chance
to be replaced. If the user replace its main board I can generate a new
installation ID for him without any problems.

Thanks.
This topic is locked and can not be replied to.