arpdb 0.1.3 → 0.1.4

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: 827b4e97497154154947b04056d2187502fc6a03
4
- data.tar.gz: 0aee24d7e749beb26cc2be65a27e69a9f706fcbb
3
+ metadata.gz: 608b55c164203c7fed6e788fd36a8c63d4f444bc
4
+ data.tar.gz: a188629f558bf677b05079a53a752f3e20ea84f0
5
5
  SHA512:
6
- metadata.gz: 8bf2b7158ce74ab84fcd31170fa5204025d3ea5b4178468752314b204f8e44fcf8d91413e84b3fc2209cafddb124a01fdb46fa134f3d5ccfcb7921272b4eb546
7
- data.tar.gz: 2417d72cff3ebf1fbf02393f3145206907624821cb06e4c8e62296f7066368ba97b062654f7ddb8f11c34627dd02b80872ebebaa3f6c7ddef6603f37534aeac1
6
+ metadata.gz: d7876ea9bcf3484de7841bba5e4c2a428b5fb8a2da8ef59a29308ee13eb7ec4ef3ec3ba18557586e2bafe43461020037dfad6b459870c5d05cec9036010b2ea9
7
+ data.tar.gz: d5bef5453a3303995c23d9f93e10166c2bb59638533bbcc4d654f1969be78860c09d43a85602122b8f9f1a87c3bf3fd8b2e071f2f1e3cdbb4105b74f614341ac
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
  /spec/reports/
10
10
  /tmp/
11
11
  *.gem
12
+ /spec_local/
13
+
data/README.md CHANGED
@@ -1,5 +1,6 @@
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
+ [![Coverage Status](https://coveralls.io/repos/jkvalk/arpdb/badge.svg?branch=master)](https://coveralls.io/r/jkvalk/arpdb?branch=master)
3
4
 
4
5
  # Arpdb
5
6
 
data/bin/console CHANGED
@@ -3,13 +3,11 @@
3
3
  require "bundler/setup"
4
4
  require "arpdb"
5
5
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
6
+ # reload a gem
7
+ def reload(require_regex)
8
+ $".grep(/^#{require_regex}/).each {|e| load(e) }
9
+ end
10
10
 
11
11
  require "pry"
12
12
  Pry.start
13
13
 
14
- #require "irb"
15
- #IRB.start
data/lib/arpdb/arp.rb CHANGED
@@ -7,27 +7,36 @@ module Arpdb
7
7
 
8
8
  class Arp
9
9
 
10
+ class ArpdbError < StandardError
11
+ end
12
+
10
13
  attr_accessor :db
11
14
 
12
15
  # * +hostlist+ - Array of hostnames (strings) who's ARP tables to fetch
13
16
  def initialize(hostlist, community = 'public')
14
17
  @hostlist = hostlist
15
18
  @community = community
19
+ @db = Array.new
16
20
  end
17
21
 
18
- # Just an alias for refresh()
19
- def scan
22
+ # Just an alias for scan
23
+ def refresh
20
24
  refresh
21
25
  end
22
26
 
23
- def refresh
24
- @db = Array.new
27
+ def scan
25
28
  @hostlist.each do |host|
26
- SNMP::Manager.open(host: host, community: @community) do |manager|
27
- manager.walk(%w(1.3.6.1.2.1.4.22.1.2 1.3.6.1.2.1.4.22.1.3)) do |row|
28
- mac = row[0].value.unpack('H*')[0]
29
- ip = row[1].value.to_s
30
- @db << {mac: mac, ip: ip, host: host}
29
+ handle_exceptions do
30
+ SNMP::Manager.open(host: host, community: @community, mib_modules: [], retries: 1) do |manager|
31
+
32
+ location = String.new
33
+ manager.get('1.3.6.1.2.1.1.6.0').each_varbind { |vb| location = vb.value }
34
+
35
+ manager.walk(%w(1.3.6.1.2.1.4.22.1.2 1.3.6.1.2.1.4.22.1.3)) do |row|
36
+ mac = row[0].value.unpack('H*').first
37
+ ip = row[1].value.to_s
38
+ @db << {mac: mac, ip: ip, host: host, location: location}
39
+ end
31
40
  end
32
41
  end
33
42
  end
@@ -38,7 +47,7 @@ module Arpdb
38
47
  # mac_to_ip("a7fea790ffa9")
39
48
  def mac_to_ip(mac)
40
49
  db.each do |line|
41
- if line[:mac].eql?(mac.downcase.gsub(':',''))
50
+ if line[:mac].eql?(mac.downcase.gsub(':', ''))
42
51
  return line[:ip]
43
52
  end
44
53
  end
@@ -56,29 +65,39 @@ module Arpdb
56
65
  ''
57
66
  end
58
67
 
59
- # Returns the host that has given MAC in it's ARP table
68
+ # Returns the syslocation that has given MAC in it's ARP table
60
69
  # * +mac+ - MAC address. String, hex, lowercase, no byte separators.
61
70
  # locate_mac("a7fea790ffa9")
62
71
  def locate_mac(mac)
63
72
  db.each do |line|
64
- if line[:mac].eql?(mac)
65
- return line[:host]
73
+ if line[:mac].eql?(mac.downcase.gsub(':', ''))
74
+ return line[:location]
66
75
  end
67
76
  end
68
77
  ''
69
78
  end
70
79
 
71
- # Returns the host that has given IP in it's ARP table
80
+ # Returns the syslocation that has given IP in it's ARP table
72
81
  # * +ip+ - IP address. String, decimal.
73
82
  # locate_mac("10.0.0.1")
74
83
  def locate_ip(ip)
75
84
  db.each do |line|
76
85
  if line[:ip].eql?(ip)
77
- return line[:host]
86
+ return line[:location]
78
87
  end
79
88
  end
80
89
  ''
81
90
  end
82
91
 
92
+ private
93
+
94
+ def handle_exceptions
95
+ begin
96
+ yield
97
+ rescue => e
98
+ raise ArpdbError, "Exception in Arpdb::Arp: #{e.to_s}"
99
+ end
100
+ end
101
+
83
102
  end
84
103
  end
data/lib/arpdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arpdb
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arpdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - J.K.Valk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-14 00:00:00.000000000 Z
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler