7

Is there a way to generate an unique Hardware dependent Identification key in Ruby...?

pankajdoharey
  • 1,562
  • 19
  • 30

3 Answers3

11

In Ruby 1.9.2 it's built in.

require 'securerandom'
puts SecureRandom.uuid
#ff97e1e1-22d4-44cf-bf5d-ef1e26444a06
steenslag
  • 79,051
  • 16
  • 138
  • 171
  • 2
    actually that is not unique. it changes everytime you invoke it. it depends on what @pankajdoharey was looking for. it it was an unique id of each hardware, your solution does not fit. – ALoR Mar 17 '11 at 13:24
  • 1
    UUIDTools timestamp_create takes mac address and current time and appears thread-safe – aceofspades Nov 17 '11 at 23:41
  • This is wrong. Even if we interpret "unique" in the loosest way possible, the question requests "hardware dependent" and Ruby's SecureRandom#uuid currently and has always generated V4 UUIDs, which are purely random: "It doesn't contain meaningful information such as MAC addresses, timestamps, etc." https://ruby-doc.org/stdlib-2.5.0/libdoc/securerandom/rdoc/Random/Formatter.html#method-i-uuid – Yuri Gadow May 11 '18 at 15:28
6

For a hardware dependent identification key, we use a MAC address.

A Media Access Control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment. MAC addresses are most often assigned by the manufacturer of a network interface card (NIC) and are stored in its hardware, the card's read-only memory, or some other firmware mechanism. [wikipedia]

Here's the gem we use.

NAME

  macaddr

DESCRIPTION

  cross platform mac address determination for ruby

URI

  http://codeforpeople.com/lib/ruby
  http://rubyforg.org/projects/codeforpeople

INSTALL

  gem install macaddr

SYNOPSIS

  require 'macaddr'

  Mac.addr      #=> first mac addr on your system
  Mac.addr.list #=> all mac addrs on your system
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
0

there are lot of gems for this. just search for:

gem search -r uuid

and pick up the one you like the most.

ALoR
  • 4,904
  • 2
  • 23
  • 25