Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Created May 31, 2012 07:44
Show Gist options
  • Save pachacamac/2841710 to your computer and use it in GitHub Desktop.
Save pachacamac/2841710 to your computer and use it in GitHub Desktop.
Mac address OUI lookup
db, oui, company, address = {}, nil, nil, ''
lines = File.readlines('oui.txt') #http://standards.ieee.org/develop/regauth/oui/oui.txt
lines.each do |line|
#line.encode!('UTF-16', 'UTF-8', :invalid => :replace, :replace => '').encode!('UTF-8', 'UTF-16').rstrip!
line = line.unpack("C*").pack("U*").rstrip
if m = line.match(/^(\d\d-\d\d-\d\d)\s+\(hex\)\s+(.*?)$/)
oui, company = m[1], m[2]
elsif oui && company && m = line.match(/^\s+(.*?)$/)
address << m[1] << "\n"
elsif oui && company && line == ''
db[oui] = [company, address]
oui, company, address = nil, nil, ''
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment