macvendors 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b154b175a6a1cdee147b9094cf41fd462488071
4
- data.tar.gz: 4864a04f2f0b27dd0376c529c1606d9ba0887576
3
+ metadata.gz: be531cefa8236a693899463d3529ecd50a423571
4
+ data.tar.gz: 5540d0154345e146786462357cff3f62c0944942
5
5
  SHA512:
6
- metadata.gz: c58a7ccc5f09d47421e7a815b0d73afb71f1e5d1ca40b27045e9d34097018acc63730d38889798244229c39a07f145e7389d8bf40bdf9ce7acc9463e688ccf6a
7
- data.tar.gz: 2dab282827c40c6f44bfb9db158b028a22caff1ae6a8d5a1819aff6fb000984d2f296d86a053c1998d80682c05e05e1150dbbd26389da09de05662103c57cef6
6
+ metadata.gz: 7f934904db785a6b550686b090ac173a50ff0d572acd6ae5147da78ec54e4ede20b6108046aae4c78d28669e0caf5211a760f105e4daf4bbb9f676f144a0383b
7
+ data.tar.gz: 9bc68c81a4a2029ab612dd16026f86ce74c81e9c76147f02a06c50d195fd73c2e15e08e31dbb37a981bb15616b244dc7d4dfe95a0a4cb524e351c0c330ca655e
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.2]
2
+ ### Edited
3
+ - Fix the slowness when querying multiple mac addresses. [76b2cca]
4
+
1
5
  ## [0.0.1]
2
6
  ### Added
3
- - macvendors find, update [05941ef]
7
+ - macvendors find, update [8c303d4]
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Bryan Lim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Macvendors
2
2
 
3
+ ![MacVendors](macvendors.gif "MacVendors")
4
+
3
5
  A command line tool to find vendor name from a mac address.
4
6
 
5
7
  No need for an external api. You can also extend it in your ruby code.
@@ -0,0 +1,15 @@
1
+ require 'macvendors'
2
+
3
+ input = ""
4
+ output = ""
5
+
6
+ #take in the csv
7
+ data = CSV.read(input)
8
+ mac_addresses = data["mac"]
9
+ puts "This csv contains no mac address column named 'mac'" if mac_addresses.count == 0
10
+ MacVendors.setup
11
+
12
+ #output
13
+ mac_addresses.times.each_with_index do |index, row|
14
+ csv << MacVendors.find(row)
15
+ end
@@ -12,15 +12,17 @@ module MacVendors
12
12
 
13
13
  desc :find, "find the vendor for this mac address"
14
14
  def find value
15
- MacVendors.find(value)
15
+ MacVendors.setup
16
+ puts MacVendors.find2(value)
16
17
  end
17
18
 
18
19
  desc :update, "update/replace the mac address csv from ieee"
19
20
  def update
21
+ MacVendors.setup
20
22
  MacVendors.update()
21
23
  end
22
24
 
23
- desc :install, "install your first oui.csv"
25
+ desc :install, "install your first vendors"
24
26
  def install
25
27
  MacVendors.download()
26
28
  end
@@ -30,33 +32,44 @@ module MacVendors
30
32
  private
31
33
 
32
34
  def self.update
33
- path_to_file = "/Users/ytbryan/.macvendors/oui.csv"
35
+ path_to_file = "#{Dir.home}/.macvendors/oui.csv"
34
36
  File.delete(path_to_file) if File.exist?(path_to_file)
35
- puts "oui.csv removed."
37
+ puts "vendors removed."
36
38
  MacVendors.download()
37
39
  end
38
40
 
39
41
 
40
42
  def self.download
41
- Dir.mkdir ".macvendors" if Dir[".macvendors"] == nil
42
- open("/Users/ytbryan/.macvendors/oui.csv", 'wb') do |file|
43
+ Dir.mkdir "#{Dir.home}/.macvendors" if File.directory?("#{Dir.home}/.macvendors") == false
44
+ open("#{Dir.home}/.macvendors/oui.csv", 'wb') do |file|
43
45
  file << open('http://standards-oui.ieee.org/oui/oui.csv').read
44
46
  end
45
- puts "downloaded oui.csv"
47
+ puts "downloaded vendors"
46
48
  end
47
49
 
48
50
  def self.search value
49
- path = "/Users/ytbryan/.macvendors/oui.csv"
50
- answer = CSV.read(path,:headers=> true, :encoding => "ISO8859-1:utf-8") #TODO: is this a data
51
- column = answer["Assignment"]
52
- name = answer["Organization Name"]
51
+ column = @answer["Assignment"]
52
+ name = @answer["Organization Name"]
53
53
  hash = Hash[column.map.with_index.to_a]
54
+ final_answer = ""
54
55
  if hash[value] != nil
55
- puts name[hash[value]]
56
+ final_answer = name[hash[value]]
56
57
  else
57
- puts "something went wrong."
58
+ final_answer = nil # "something went wrong."
58
59
  end
59
- return answer
60
+ return final_answer
61
+ end
62
+
63
+ def self.setup
64
+ path = "#{Dir.home}/.macvendors/oui.csv"
65
+ @answer = CSV.read(path,:headers=> true, :encoding => "ISO8859-1:utf-8") #TODO: is this a data
66
+ end
67
+
68
+ def self.find2 string
69
+ MacVendors.setup
70
+ string = string.gsub(":", "")
71
+ string = string.gsub("-", "")
72
+ return search(string[0..5].upcase)
60
73
  end
61
74
 
62
75
  def self.find string
@@ -1,3 +1,3 @@
1
1
  module MacVendors
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
Binary file
@@ -1,4 +1,5 @@
1
1
  require 'macvendors'
2
2
 
3
- MacVendors.find("98:e0:d9:a5:61:eb")
3
+ MacVendors.setup
4
+ puts MacVendors.find("98:e0:d9:a5:61:eb")
4
5
  MacVendors.update()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macvendors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Lim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-17 00:00:00.000000000 Z
11
+ date: 2016-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,15 +50,18 @@ files:
50
50
  - CHANGELOG
51
51
  - CODE_OF_CONDUCT.md
52
52
  - Gemfile
53
+ - LICENSE
53
54
  - LICENSE.txt
54
55
  - README.md
55
56
  - Rakefile
56
57
  - bin/console
57
58
  - bin/macvendors
58
59
  - bin/setup
60
+ - example.rb
59
61
  - lib/macvendors.rb
60
62
  - lib/macvendors/version.rb
61
63
  - macvendors.gemspec
64
+ - macvendors.gif
62
65
  - tests/test.rb
63
66
  homepage: https://github.com/ytbryan/macvendors
64
67
  licenses: