arpdb 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb885013b5a04ca2912a9ad3258f9e6bb328f9f7
4
+ data.tar.gz: 31de24183490c2065f51ff1afab4a10200c64f96
5
+ SHA512:
6
+ metadata.gz: f9294f9a98b874aba5885ae42a851ff70c749ea2791d8b55377f5ccf98a28f6efe4b4d6e7b6339022b0545c72b955abfaf883de1b59fd81d85fc07d254dcba65
7
+ data.tar.gz: 5e6b4bfb330950762a47c45b2c968f2fc53e14c53a460a3c7573ae6758e4445333f4156b77512936047da716ab2a833cf8c4628ceedbf4a92482f7336821da22
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  [![Build Status](https://travis-ci.org/jkvalk/arpdb.svg?branch=master)](https://travis-ci.org/jkvalk/arpdb)
2
2
  [![Gem Version](https://badge.fury.io/rb/arpdb.svg)](http://badge.fury.io/rb/arpdb)
3
3
  [![Coverage Status](https://coveralls.io/repos/jkvalk/arpdb/badge.svg?branch=master)](https://coveralls.io/r/jkvalk/arpdb?branch=master)
4
+ [![Code Climate](https://codeclimate.com/github/jkvalk/arpdb/badges/gpa.svg)](https://codeclimate.com/github/jkvalk/arpdb)
4
5
 
5
6
  # Arpdb
6
7
 
@@ -30,7 +31,7 @@ include Arpdb
30
31
  hosts = %w(10.40.5.1 10.43.5.1)
31
32
  community = 'public'
32
33
 
33
- adb = Arp.new(hosts.collect { |host| SNMPTransport.new(host, community) }).scan
34
+ adb = Arp.new( hosts.collect { |host| SNMPTransport.new(host, community) } ).scan
34
35
 
35
36
  puts adb.mac_to_ip "7a70dec81b02"
36
37
  puts adb.ip_to_mac "172.27.50.2"
@@ -44,9 +45,7 @@ adb.rescan
44
45
 
45
46
  ## Development
46
47
 
47
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
-
49
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
49
 
51
50
  ## Contributing
52
51
 
data/lib/arpdb/arp.rb CHANGED
@@ -37,47 +37,19 @@ module Arpdb
37
37
  end
38
38
 
39
39
  def mac_to_ip(mac)
40
- return '' if mac.nil?
41
-
42
- db.each do |line|
43
- if line[:mac].eql?(mac.downcase.gsub(':', ''))
44
- return line[:ip]
45
- end
46
- end
47
- String.new
40
+ dblookup(:mac, mac_flatten(mac), :ip)
48
41
  end
49
42
 
50
43
  def ip_to_mac(ip)
51
- return '' if ip.nil?
52
-
53
- db.each do |line|
54
- if line[:ip].eql?(ip)
55
- return line[:mac]
56
- end
57
- end
58
- String.new
44
+ dblookup(:ip, ip, :mac)
59
45
  end
60
46
 
61
47
  def locate_mac(mac)
62
- return '' if mac.nil?
63
-
64
- db.each do |line|
65
- if line[:mac].eql?(mac.downcase.gsub(':', ''))
66
- return line[:location]
67
- end
68
- end
69
- String.new
48
+ dblookup(:mac, mac_flatten(mac), :location)
70
49
  end
71
50
 
72
51
  def locate_ip(ip)
73
- return '' if ip.nil?
74
-
75
- db.each do |line|
76
- if line[:ip].eql?(ip)
77
- return line[:location]
78
- end
79
- end
80
- String.new
52
+ dblookup(:ip, ip, :location)
81
53
  end
82
54
 
83
55
  private
@@ -90,5 +62,17 @@ module Arpdb
90
62
  end
91
63
  end
92
64
 
65
+ def dblookup(key, match_value, return_key)
66
+ return '' if match_value.nil?
67
+
68
+ line = db.find { |line| line[key].eql?(match_value) }
69
+ line ? line[return_key] : ''
70
+ end
71
+
72
+ def mac_flatten(mac)
73
+ return '' if mac.nil?
74
+ mac.downcase.gsub(':', '')
75
+ end
76
+
93
77
  end
94
78
  end
data/lib/arpdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arpdb
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,142 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arpdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - J.K.Valk
9
8
  autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-06-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.10'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.10'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: guard
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: guard-rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: coveralls
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: pry
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: snmp
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ~>
115
+ - - "~>"
132
116
  - !ruby/object:Gem::Version
133
117
  version: '1.2'
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ~>
122
+ - - "~>"
140
123
  - !ruby/object:Gem::Version
141
124
  version: '1.2'
142
125
  description: This is VERY raw, version 1.0.0 is expected to be first usable implementation.
@@ -146,13 +129,12 @@ executables: []
146
129
  extensions: []
147
130
  extra_rdoc_files: []
148
131
  files:
149
- - .coveralls.yml
150
- - .gitignore
151
- - .rspec
152
- - .travis.yml
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
153
136
  - CODE_OF_CONDUCT.md
154
137
  - Gemfile
155
- - Guardfile
156
138
  - README.md
157
139
  - Rakefile
158
140
  - arpdb.gemspec
@@ -165,27 +147,26 @@ files:
165
147
  homepage: https://github.com/jkvalk/arpdb
166
148
  licenses:
167
149
  - MIT
150
+ metadata: {}
168
151
  post_install_message:
169
152
  rdoc_options: []
170
153
  require_paths:
171
154
  - lib
172
155
  required_ruby_version: !ruby/object:Gem::Requirement
173
- none: false
174
156
  requirements:
175
- - - ! '>='
157
+ - - ">="
176
158
  - !ruby/object:Gem::Version
177
159
  version: '0'
178
160
  required_rubygems_version: !ruby/object:Gem::Requirement
179
- none: false
180
161
  requirements:
181
- - - ! '>='
162
+ - - ">="
182
163
  - !ruby/object:Gem::Version
183
164
  version: '0'
184
165
  requirements: []
185
166
  rubyforge_project:
186
- rubygems_version: 1.8.23
167
+ rubygems_version: 2.2.2
187
168
  signing_key:
188
- specification_version: 3
169
+ specification_version: 4
189
170
  summary: Arpdb is a Ruby gem for querying SNMP-enabled network devices for their ARP
190
171
  database.
191
172
  test_files: []
data/Guardfile DELETED
@@ -1,70 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- ## Uncomment and set this to only include directories you want to watch
5
- # directories %w(app lib config test spec features) \
6
- # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
-
8
- ## Note: if you are using the `directories` clause above and you are not
9
- ## watching the project directory ('.'), then you will want to move
10
- ## the Guardfile to a watched dir and symlink it back, e.g.
11
- #
12
- # $ mkdir config
13
- # $ mv Guardfile config/
14
- # $ ln -s config/Guardfile .
15
- #
16
- # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
-
18
- # Note: The cmd option is now required due to the increasing number of ways
19
- # rspec may be run, below are examples of the most common uses.
20
- # * bundler: 'bundle exec rspec'
21
- # * bundler binstubs: 'bin/rspec'
22
- # * spring: 'bin/rspec' (This will use spring if running and you have
23
- # installed the spring binstubs per the docs)
24
- # * zeus: 'zeus rspec' (requires the server to be started separately)
25
- # * 'just' rspec: 'rspec'
26
-
27
- guard :rspec, cmd: "bundle exec rspec" do
28
- require "guard/rspec/dsl"
29
- dsl = Guard::RSpec::Dsl.new(self)
30
-
31
- # Feel free to open issues for suggestions and improvements
32
-
33
- # RSpec files
34
- rspec = dsl.rspec
35
- watch(rspec.spec_helper) { rspec.spec_dir }
36
- watch(rspec.spec_support) { rspec.spec_dir }
37
- watch(rspec.spec_files)
38
-
39
- # Ruby files
40
- ruby = dsl.ruby
41
- dsl.watch_spec_files_for(ruby.lib_files)
42
-
43
- # Rails files
44
- rails = dsl.rails(view_extensions: %w(erb haml slim))
45
- dsl.watch_spec_files_for(rails.app_files)
46
- dsl.watch_spec_files_for(rails.views)
47
-
48
- watch(rails.controllers) do |m|
49
- [
50
- rspec.spec.("routing/#{m[1]}_routing"),
51
- rspec.spec.("controllers/#{m[1]}_controller"),
52
- rspec.spec.("acceptance/#{m[1]}")
53
- ]
54
- end
55
-
56
- # Rails config changes
57
- watch(rails.spec_helper) { rspec.spec_dir }
58
- watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
- watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
-
61
- # Capybara features specs
62
- watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
63
- watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
64
-
65
- # Turnip features and steps
66
- watch(%r{^spec/acceptance/(.+)\.feature$})
67
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
- Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
- end
70
- end