Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique System ID in Ruby ...?

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

like image 496
pankajdoharey Avatar asked Mar 17 '11 12:03

pankajdoharey


2 Answers

In Ruby 1.9.2 it's built in.

require 'securerandom'
puts SecureRandom.uuid
#ff97e1e1-22d4-44cf-bf5d-ef1e26444a06
like image 137
steenslag Avatar answered Sep 20 '22 23:09

steenslag


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
like image 33
joelparkerhenderson Avatar answered Sep 20 '22 23:09

joelparkerhenderson