oui 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/bin/oui +30 -0
- data/data/oui.txt +123537 -0
- data/data/translations.yml +1025 -0
- data/lib/oui.rb +6 -0
- data/lib/oui/address.rb +5 -0
- data/lib/oui/database.rb +30 -0
- data/lib/oui/mac_address.rb +40 -0
- data/lib/oui/organization.rb +13 -0
- data/lib/oui/version.rb +3 -0
- data/oui.gemspec +26 -0
- data/spec/oui/address_spec.rb +10 -0
- data/spec/oui/database_spec.rb +9 -0
- data/spec/oui/mac_address_spec.rb +61 -0
- data/spec/oui/organization_spec.rb +17 -0
- data/spec/spec_helper.rb +2 -0
- metadata +122 -0
data/lib/oui.rb
ADDED
data/lib/oui/address.rb
ADDED
data/lib/oui/database.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module OUI
|
2
|
+
class Database
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@@file = File.read(File.expand_path('../../../data/oui.txt', __FILE__))
|
6
|
+
@@oui_to_organization_names = {}
|
7
|
+
|
8
|
+
@@file.each_line do |line|
|
9
|
+
regex = /(#{MACAddress.oui_regex_string})\s+\(hex\)\s+(.+)/
|
10
|
+
if line =~ regex
|
11
|
+
@@oui_to_organization_names[$1] = $2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def look_up_organization_by_oui(oui)
|
17
|
+
organization = Organization.new
|
18
|
+
organization.name = @@oui_to_organization_names[oui.upcase]
|
19
|
+
organization
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def look_up_organization_by_oui(oui)
|
24
|
+
@@instance ||= new
|
25
|
+
|
26
|
+
@@instance.look_up_organization_by_oui(oui)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module OUI
|
2
|
+
class MACAddress
|
3
|
+
attr_accessor :oui, :organization
|
4
|
+
|
5
|
+
@@part = '[\d|[a-f]|[A-F]][\d|[a-f]|[A-F]]'
|
6
|
+
|
7
|
+
def self.parse(string)
|
8
|
+
new(string)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.oui_regex
|
12
|
+
/#{self.oui_regex_string}/
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.oui_regex_string
|
16
|
+
"#{@@part}-#{@@part}-#{@@part}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.part
|
20
|
+
@@part
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(string)
|
24
|
+
string =~ /(#{@@part})[:-]?(#{@@part})[:-]?(#{@@part})[:-]?(#{@@part})[:-]?(#{@@part})[:-]?(#{@@part})/
|
25
|
+
|
26
|
+
@address = "#{$1}:#{$2}:#{$3}:#{$4}:#{$5}:#{$6}"
|
27
|
+
@oui = "#{$1}-#{$2}-#{$3}"
|
28
|
+
|
29
|
+
raise 'illegal format' if @address == ':::::'
|
30
|
+
end
|
31
|
+
|
32
|
+
def organization
|
33
|
+
unless @organization
|
34
|
+
@organization = Database.look_up_organization_by_oui(@oui)
|
35
|
+
end
|
36
|
+
|
37
|
+
@organization
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/oui/version.rb
ADDED
data/oui.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oui/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oui"
|
8
|
+
spec.version = OUI::VERSION
|
9
|
+
spec.authors = ["Forrest Ye"]
|
10
|
+
spec.email = ["afu@forresty.com"]
|
11
|
+
spec.description = %q{look up OUI information /w Chinese translation using MAC addresses}
|
12
|
+
spec.summary = %q{look up OUI information /w Chinese translation using MAC addresses}
|
13
|
+
spec.homepage = "https://github.com/modouwifi/oui-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module OUI
|
4
|
+
describe MACAddress do
|
5
|
+
subject { MACAddress }
|
6
|
+
|
7
|
+
it { should respond_to :parse }
|
8
|
+
it { should respond_to :oui_regex }
|
9
|
+
|
10
|
+
describe "parse" do
|
11
|
+
subject { MACAddress }
|
12
|
+
|
13
|
+
it "parses MAC address like 001122334455" do
|
14
|
+
expect(subject.parse('001122334455')).not_to be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "parses MAC address like 00-11-22-33-44-55" do
|
18
|
+
expect(subject.parse('00-11-22-33-44-55')).not_to be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "parses MAC address like 00:11:22:33:44:55" do
|
22
|
+
expect(subject.parse('00:11:22:33:44:55')).not_to be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "does not parse MAC address like 00:11:22:3344" do
|
26
|
+
expect { subject.parse('00:11:22:3344') }.to raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it "parses MAC address like 00:11:22:33:aa:bb" do
|
30
|
+
expect(subject.parse('00:11:22:33:aa:bb')).not_to be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "parses MAC address like 00:11:22:33:AA:BB" do
|
34
|
+
expect(subject.parse('00:11:22:33:AA:BB')).not_to be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "instance methods" do
|
39
|
+
subject { MACAddress.parse('001122334455') }
|
40
|
+
|
41
|
+
it { should respond_to :oui }
|
42
|
+
it { should respond_to :organization }
|
43
|
+
|
44
|
+
describe "oui" do
|
45
|
+
it "extracts oui from mac address" do
|
46
|
+
expect(subject.oui).to eq('00-11-22')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "parses organization from database" do
|
50
|
+
real_mac_address = '14:10:9f:ea:49:3e'
|
51
|
+
|
52
|
+
expect(Database).to receive(:look_up_organization_by_oui).and_return(Organization.new { |o| o.name = 'Apple' })
|
53
|
+
|
54
|
+
organization = MACAddress.parse(real_mac_address).organization
|
55
|
+
|
56
|
+
expect(organization.name).to eq('Apple')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module OUI
|
4
|
+
describe Organization do
|
5
|
+
subject { Organization }
|
6
|
+
|
7
|
+
it { should respond_to :parse }
|
8
|
+
|
9
|
+
describe "instance methods" do
|
10
|
+
subject { Organization.new }
|
11
|
+
|
12
|
+
it { should respond_to :name }
|
13
|
+
it { should respond_to :address }
|
14
|
+
it { should respond_to :chinese_name }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oui
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Forrest Ye
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: &70292318938300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70292318938300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70292318937300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70292318937300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70292318936260 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70292318936260
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: &70292318934680 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70292318934680
|
58
|
+
description: look up OUI information /w Chinese translation using MAC addresses
|
59
|
+
email:
|
60
|
+
- afu@forresty.com
|
61
|
+
executables:
|
62
|
+
- oui
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/oui
|
72
|
+
- data/oui.txt
|
73
|
+
- data/translations.yml
|
74
|
+
- lib/oui.rb
|
75
|
+
- lib/oui/address.rb
|
76
|
+
- lib/oui/database.rb
|
77
|
+
- lib/oui/mac_address.rb
|
78
|
+
- lib/oui/organization.rb
|
79
|
+
- lib/oui/version.rb
|
80
|
+
- oui.gemspec
|
81
|
+
- spec/oui/address_spec.rb
|
82
|
+
- spec/oui/database_spec.rb
|
83
|
+
- spec/oui/mac_address_spec.rb
|
84
|
+
- spec/oui/organization_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
homepage: https://github.com/modouwifi/oui-gem
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: 4091341631570692659
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: 4091341631570692659
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.11
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: look up OUI information /w Chinese translation using MAC addresses
|
117
|
+
test_files:
|
118
|
+
- spec/oui/address_spec.rb
|
119
|
+
- spec/oui/database_spec.rb
|
120
|
+
- spec/oui/mac_address_spec.rb
|
121
|
+
- spec/oui/organization_spec.rb
|
122
|
+
- spec/spec_helper.rb
|