Module: MacAddressEui48
- Defined in:
- lib/mac_address_eui48/version.rb,
lib/mac_address_eui48.rb,
lib/mac_address_eui48/mac_address.rb,
lib/mac_address_eui48/oui_resolver.rb
Overview
Copyright © 2015 Mathieu Cunche <[email protected]>
Defined Under Namespace
Classes: MacAddress, OuiResolver
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .int_to_str_mac(i, sep = ':') ⇒ Object
-
.is_valid_mac(mac_addr) ⇒ Object
MAC address format is hexadecimal characters separated by ‘:’ ex: “AA:BB:CC:DD:EE:FF” or “11:22:33:44:55:66.
- .oui_lookup(mac_addr) ⇒ Object
- .str_mac_to_int(a) ⇒ Object
Class Method Details
.int_to_str_mac(i, sep = ':') ⇒ Object
21 22 23 24 25 26 |
# File 'lib/mac_address_eui48.rb', line 21 def MacAddressEui48::int_to_str_mac(i,sep=':') a = i.to_s(16) a = a.rjust(12,'0') a = a.insert(10,sep).insert(8,sep).insert(6,sep).insert(4,sep).insert(2,sep) return a.upcase end |
.is_valid_mac(mac_addr) ⇒ Object
MAC address format is hexadecimal characters separated by ‘:’ ex: “AA:BB:CC:DD:EE:FF” or “11:22:33:44:55:66
13 14 15 |
# File 'lib/mac_address_eui48.rb', line 13 def MacAddressEui48::is_valid_mac(mac_addr) return (mac_addr =~ /^(\h\h:){5}\h\h$/) end |
.oui_lookup(mac_addr) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mac_address_eui48.rb', line 28 def MacAddressEui48::oui_lookup(mac_addr) oui = "" mac_array=mac_addr.upcase.split(":") prefix = mac_array[0] + "-" + mac_array[1] + "-" + mac_array[2] path = File.('../../data/oui.txt', __FILE__) oui_file = File.open(path) oui_file.each_line do |line| if (line =~ /.*#{prefix}.*(hex)/) then oui = line.split("\t")[2].chomp end end return oui end |
.str_mac_to_int(a) ⇒ Object
17 18 19 |
# File 'lib/mac_address_eui48.rb', line 17 def MacAddressEui48::str_mac_to_int(a) return a = a.delete(":").to_i(16) end |