arp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/arp.gemspec +22 -0
- data/lib/arp.rb +35 -0
- data/lib/arp/version.rb +3 -0
- data/spec/arp_spec.rb +42 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/test_files/arp +6 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4d1d48aba8ab658417296548c70349e9ed085dcd
|
4
|
+
data.tar.gz: 08292369e7449c17b6276ac22266bb65d06bbffa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f9ea52597a79740bd8de552142da9f49a42dfbdbc661cf7bc5ed0cbd10f4e473d2c268a970e01e62a796e1a3b294b77b1a5df9c4662ba09b6b6fe5aa1068864d
|
7
|
+
data.tar.gz: 08c16ce31fb192164ec192c0cde491ce821da3eb1cd6ce9d47f44c6f247b712d2b2d3a94c67a224338f87dc188f426c6b0feb82ce16993757fe6173f7aecf899
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Simon Mathieu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Arp
|
2
|
+
|
3
|
+
Retrieve the content of the ARP cache
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'arp'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install arp
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
cache = Arp::Cache.new
|
23
|
+
cache.each do |entry|
|
24
|
+
puts entry.ip # => "192.168.124.2"
|
25
|
+
puts entry.hw_type # => "0x1"
|
26
|
+
puts entry.flags # => "0x2"
|
27
|
+
puts entry.hw_address # => "00:50:56:e9:27:c7"
|
28
|
+
puts entry.mask # => "*"
|
29
|
+
puts entry.device # => "eth0"
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Limitation
|
34
|
+
|
35
|
+
Currently works only on Linux. Tested on Ubuntu 12.04.
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( http://github.com/<my-github-username>/arp/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/arp.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arp"
|
8
|
+
spec.version = Arp::VERSION
|
9
|
+
spec.authors = ["Simon Mathieu"]
|
10
|
+
spec.email = ["simon.math@gmail.com"]
|
11
|
+
spec.summary = %q{Retrieve the content of the ARP cache}
|
12
|
+
spec.homepage = "https://github.com/rainforestapp/arp"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/lib/arp.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "arp/version"
|
2
|
+
require 'forwardable'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Arp
|
6
|
+
class Cache
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
extend Forwardable
|
10
|
+
def_delegators :collection, :each, :<<, :size
|
11
|
+
|
12
|
+
|
13
|
+
attr_reader :path
|
14
|
+
|
15
|
+
def initialize(path = "/proc/net/arp")
|
16
|
+
raise ArgumentError, "No such file: #{path}" unless File.exists?(path)
|
17
|
+
@path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def collection
|
21
|
+
@collection ||= File.open(@path) do |f|
|
22
|
+
f.readlines[1..-1].map do |line|
|
23
|
+
columns = line.split(/\s+/)
|
24
|
+
ip, hw_type, flags, hw_address, mask, device = *columns
|
25
|
+
OpenStruct.new(ip: ip,
|
26
|
+
hw_type: hw_type,
|
27
|
+
flags: flags,
|
28
|
+
hw_address: hw_address,
|
29
|
+
mask: mask,
|
30
|
+
device: device)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/arp/version.rb
ADDED
data/spec/arp_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Arp::Cache do
|
4
|
+
let(:file) { File.join(__dir__, "test_files/arp") }
|
5
|
+
subject { described_class.new(file) }
|
6
|
+
|
7
|
+
describe "#size" do
|
8
|
+
subject { super().size }
|
9
|
+
it { should == 5 }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#each" do
|
13
|
+
it "yields once for each line" do
|
14
|
+
i = 0
|
15
|
+
subject.each do |obj|
|
16
|
+
i += 1
|
17
|
+
end
|
18
|
+
i.should == 5
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "collection elements" do
|
23
|
+
subject { super().collection.first }
|
24
|
+
|
25
|
+
its(:ip) { should == "192.168.124.2" }
|
26
|
+
its(:hw_type) { should == "0x1" }
|
27
|
+
its(:flags) { should == "0x2" }
|
28
|
+
its(:hw_address) { should == "00:50:56:e9:27:c7" }
|
29
|
+
its(:mask) { should == "*" }
|
30
|
+
its(:device) { should == "eth0" }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#initialize" do
|
34
|
+
let(:file) { "does not exist" }
|
35
|
+
|
36
|
+
it "raises an exception on non existant path" do
|
37
|
+
expect do
|
38
|
+
subject
|
39
|
+
end.to raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'arp'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
data/spec/test_files/arp
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
IP address HW type Flags HW address Mask Device
|
2
|
+
192.168.124.2 0x1 0x2 00:50:56:e9:27:c7 * eth0
|
3
|
+
192.168.124.254 0x1 0x2 00:50:56:fa:9b:30 * eth0
|
4
|
+
10.0.0.1 0x1 0x2 00:50:56:c0:00:02 * eth1
|
5
|
+
192.168.124.1 0x1 0x2 00:50:56:c0:00:08 * eth0
|
6
|
+
192.168.123.10 0x1 0x2 00:34:5f:2f:7c:9c * virbr1
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Mathieu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- simon.math@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- arp.gemspec
|
55
|
+
- lib/arp.rb
|
56
|
+
- lib/arp/version.rb
|
57
|
+
- spec/arp_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- spec/test_files/arp
|
60
|
+
homepage: https://github.com/rainforestapp/arp
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Retrieve the content of the ARP cache
|
84
|
+
test_files:
|
85
|
+
- spec/arp_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/test_files/arp
|