Class: Nmunch::MacOuiLookup

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/nmunch/mac_oui_lookup.rb

Overview

Public: A utility class to look up a MAC address prefix to get the organizational name.

Instance Method Summary collapse

Instance Method Details

#lookup(mac_address) ⇒ Object

Public: Get organizational name for a MAC address

mac_address - A MAC address with format: hh:hh:hh:hh:hh:hh

Example:

Nmunch::MacOuiLookup.instance.lookup('58:b0:35:31:33:73')
# => Apple

Returns name of organization or Unknown if prefix can’t be found



19
20
21
22
23
# File 'lib/nmunch/mac_oui_lookup.rb', line 19

def lookup(mac_address)
  load_prefix_file! if @prefixes.nil?
  oui = mac_address[0..7].upcase.gsub(':', '').to_sym
  @prefixes[oui] || 'Unknown'
end