whiff 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 89a4e377d396fd2d1f9e6877c6db0682acfc53cb
4
+ data.tar.gz: 3dafb788f5ca88a0e7cab3926151e181206652ce
5
+ SHA512:
6
+ metadata.gz: e869d03bb40beb6daa5b746bfd596af045b40e767654662bfa86632aa59771dc55c8c26dc4d1f12efb1db10b8470cef2046593dad41d39a77123416f7633f125
7
+ data.tar.gz: 6b74c227f2b3f11d85e80c25cc266aeb7ef6db37681fadbc217b28b8de05ff94eba208d20399186d1677b0ea83b2b06e1a980b451ce001a7171ee07c248279f0
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ .DS_Store
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ script: bundle exec rspec spec
7
+ cache: apt
8
+ before_install:
9
+ - sudo apt-get update -qq
10
+ - sudo apt-get install -qq arp-scan
data/CHANGES.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ whiff (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ awesome_print (1.2.0)
10
+ coderay (1.1.0)
11
+ diff-lcs (1.2.5)
12
+ method_source (0.8.2)
13
+ pry (0.9.12.6)
14
+ coderay (~> 1.0)
15
+ method_source (~> 0.8)
16
+ slop (~> 3.4)
17
+ rake (10.3.0)
18
+ rspec (2.14.1)
19
+ rspec-core (~> 2.14.0)
20
+ rspec-expectations (~> 2.14.0)
21
+ rspec-mocks (~> 2.14.0)
22
+ rspec-core (2.14.8)
23
+ rspec-expectations (2.14.5)
24
+ diff-lcs (>= 1.1.3, < 2.0)
25
+ rspec-mocks (2.14.6)
26
+ slop (3.5.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ awesome_print
33
+ bundler (~> 1.6)
34
+ pry
35
+ rake (~> 10.3.0)
36
+ rspec (~> 2.14)
37
+ whiff!
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Chase Southard
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 ADDED
@@ -0,0 +1,64 @@
1
+ # whiff
2
+
3
+ _catch a whiff of this._
4
+
5
+ an interface to sniffing MAC addresses on the local network through [arp-scan](http://www.nta-monitor.com/wiki/index.php/Arp-scan_Documentation).
6
+
7
+ [![Build Status](https://travis-ci.org/chaserx/whiff.svg?branch=master)](https://travis-ci.org/chaserx/whiff)
8
+
9
+ ## Getting Started
10
+
11
+ **installing arp-scan**
12
+
13
+ mac os x:
14
+
15
+ 1. brew update
16
+ 1. brew install arp-scan
17
+
18
+ linux:
19
+
20
+ 1. sudo apt-get update
21
+ 1. sudo apt-get intall arp-scan
22
+
23
+ **arp-scan usage**
24
+
25
+ on mac os x, try:
26
+
27
+ `sudo arp-scan -l -s 10.0.1.1 -I en1 -q`
28
+
29
+ where 10.0.1.1 is the IP address of your router, and en1 is the name of your active network interface.
30
+
31
+ on linux, try:
32
+
33
+ `sudo arp-scan -l -s 10.0.1.1 -I wlan0 -q`
34
+
35
+ where 10.0.1.1 is the IP address of your router, and wlan0 is the name of your active network interface.
36
+
37
+ either of these should return something similar to the following:
38
+
39
+ Interface: en1, datalink type: EN10MB (Ethernet)
40
+ Starting arp-scan 1.8 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
41
+ 10.0.1.29 00:13:21:c1:28:9a
42
+ 10.0.1.4 20:c9:d0:b5:61:21
43
+ 10.0.1.3 8c:3a:e3:98:81:2d
44
+ 10.0.1.8 94:94:26:95:09:f0
45
+ 10.0.1.2 00:00:48:64:11:ef
46
+ 10.0.1.200 b8:27:eb:13:65:e7
47
+
48
+ 537 packets received by filter, 0 packets dropped by kernel
49
+ Ending arp-scan 1.8: 256 hosts scanned in 1.171 seconds (218.62 hosts/sec). 6 responded
50
+
51
+ **whiff usage**
52
+
53
+ `sudo irb -r whiff`
54
+
55
+ `Whiff::ArpScan.fetch('10.0.1.1', 'en1', verbose: true)`
56
+
57
+ results in:
58
+
59
+ 00:13:21:c1:28:9a
60
+ 20:c9:d0:b5:61:21
61
+ 8c:3a:e3:98:81:2d
62
+ 94:94:26:95:09:f0
63
+ 00:00:48:64:11:ef
64
+ b8:27:eb:13:65:e7
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ exec "irb -r whiff -I ./lib"
5
+ end
data/lib/whiff.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'whiff/version'
2
+ require 'whiff/arp_scan'
3
+
4
+ begin
5
+ require "pry"
6
+ rescue LoadError
7
+ end
8
+
9
+ module Whiff
10
+ end
@@ -0,0 +1,33 @@
1
+ module Whiff
2
+ module ArpScan
3
+
4
+ IP_ADDRESS_REGEX = /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/
5
+
6
+ MAC_ADDRESS_REGEX = /([0-9A-F]{2}[:]){5}([0-9A-F]{2})/i
7
+
8
+ def self.fetch(ip_address, interface, options={})
9
+ raise 'Must run as root' unless options[:test] == true || Process.uid == 0
10
+ raise 'arp-scan not installed' unless arp_scan_installed?
11
+ raise 'invalid IP address' unless ip_address =~ IP_ADDRESS_REGEX
12
+ cmd = "#{options[:env]} arp-scan -l -s #{ip_address} -I #{interface} -q"
13
+ puts cmd
14
+ addresses = []
15
+ stdout = `#{cmd}`
16
+ stdout.each_line do |line|
17
+ addresses << extract_mac_address(line)
18
+ end
19
+ addresses.delete_if{|a| a.nil?}.uniq!
20
+ puts addresses if options[:verbose]
21
+ addresses
22
+ end
23
+
24
+ def self.extract_mac_address(str)
25
+ str.match(MAC_ADDRESS_REGEX) { |m| m }
26
+ end
27
+
28
+ def self.arp_scan_installed?
29
+ `which arp-scan`
30
+ $?.success?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Whiff
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,7 @@
1
+ Interface: en1, datalink type: EN10MB (Ethernet)
2
+ Starting arp-scan 1.8 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
3
+ 10.0.1.7 b8:8d:12:59:43:b9
4
+ 10.0.1.29 00:13:21:c1:28:9a
5
+
6
+ 519 packets received by filter, 0 packets dropped by kernel
7
+ Ending arp-scan 1.8: 256 hosts scanned in 1.176 seconds (217.69 hosts/sec). 2 responded
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require 'digest/md5'
3
+ require 'open3'
4
+ require 'fileutils'
5
+
6
+ # from: http://3till7.net/2014/01/24/vcr-for-shell-scripts/index.html
7
+
8
+ command = ARGV.join(' ')
9
+ program = File.basename(ARGV.shift)
10
+ # Compute a hash of the command being run, including its arguments:
11
+ hash = Digest::MD5.hexdigest(program + ARGV.join(' '))
12
+ test_data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
13
+ fixtures = File.join(test_data_dir, program, hash)
14
+ stdout_path = File.join(fixtures, 'stdout')
15
+ stderr_path = File.join(fixtures, 'stderr')
16
+ exit_code_path = File.join(fixtures, 'exit_code')
17
+
18
+ # If we can't find a directory for this particular command, we need to
19
+ # record new cassettes.
20
+ unless Dir.exists?(fixtures)
21
+ FileUtils.mkdir_p fixtures
22
+ stdin, stdout, stderr, wait_thr = Open3.popen3(command)
23
+ stdin.close # Assume no further input necessary for the command
24
+ output = stdout.read
25
+ error = stderr.read
26
+ exit_code = wait_thr.value.exitstatus
27
+ # Write cassettes:
28
+ File.open(stdout_path, 'w') {|file| file.puts output }
29
+ File.open(stderr_path, 'w') {|file| file.puts error }
30
+ File.open(exit_code_path, 'w') {|file| file.puts exit_code }
31
+ end
32
+
33
+ # This script responds just as the actual program did, writing the same
34
+ # data to stdout and stderr, exiting with the same exit code.
35
+ $stdout.print File.read(stdout_path)
36
+ $stderr.print File.read(stderr_path)
37
+ exit File.read(exit_code_path).to_i
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bash
2
+ act-like.rb /usr/local/bin/arp-scan "$@"
@@ -0,0 +1,18 @@
1
+ require "whiff"
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # Require this file using `require "spec_helper"` to ensure that it is only
5
+ # loaded once.
6
+ #
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ module Whiff::ArpScan
4
+ describe "fetching MAC addresses through arp-scan" do
5
+ let(:bin_dir) { File.join('spec', 'data', 'bin') }
6
+ let(:path_env) { File.expand_path(bin_dir) }
7
+ let(:env) { "PATH=#{path_env}:$PATH" }
8
+
9
+ it "returns an array" do
10
+ output = Whiff::ArpScan.fetch('10.0.1.1', 'en1', test: true, env: env)
11
+ expect(output.class).to eq(Array)
12
+ end
13
+
14
+ it "returns MAC address from output" do
15
+ def output
16
+ <<-OUTPUT.gsub(/^ {4}/, '')
17
+ Interface: en1, datalink type: EN10MB (Ethernet)
18
+ Starting arp-scan 1.8 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
19
+ 10.0.1.7 b8:8d:12:59:43:b9
20
+ 10.0.1.29 00:13:21:c1:28:9a
21
+
22
+ 519 packets received by filter, 0 packets dropped by kernel
23
+ Ending arp-scan 1.8: 256 hosts scanned in 1.176 seconds (217.69 hosts/sec). 2 responded
24
+ OUTPUT
25
+ end
26
+
27
+ expect(Whiff::ArpScan.extract_mac_address(output)[0]).to include("b8:8d:12:59:43:b9")
28
+ end
29
+
30
+ it "returns an array of MAC addresses" do
31
+ output = Whiff::ArpScan.fetch('10.0.1.1', 'en1', test: true, env: env)
32
+ expect(output.size).to be > 0
33
+ expect(output[0].to_s).to match(MAC_ADDRESS_REGEX)
34
+ end
35
+ end
36
+ end
data/whiff.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 'whiff/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whiff"
8
+ spec.version = Whiff::VERSION
9
+ spec.authors = ["Chase Southard"]
10
+ spec.email = ["chase.southard@gmail.com"]
11
+ spec.summary = %q{A ruby wrapper for arp-scan.}
12
+ spec.description = %q{A ruby wrapper for arp-scan. Currently, returns an array of MAC addresses.}
13
+ spec.homepage = "https://github.com/chaserx/whiff"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6"
22
+ spec.add_development_dependency "rake", "~> 10.3.0"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+ spec.add_development_dependency "awesome_print"
25
+ spec.add_development_dependency "pry"
26
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whiff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chase Southard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-21 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 10.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 10.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A ruby wrapper for arp-scan. Currently, returns an array of MAC addresses.
84
+ email:
85
+ - chase.southard@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - CHANGES.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - lib/whiff.rb
100
+ - lib/whiff/arp_scan.rb
101
+ - lib/whiff/version.rb
102
+ - spec/data/arp-scan/9489ad861b94a4dd85e0b7faa03e6dd1/exit_code
103
+ - spec/data/arp-scan/9489ad861b94a4dd85e0b7faa03e6dd1/stderr
104
+ - spec/data/arp-scan/9489ad861b94a4dd85e0b7faa03e6dd1/stdout
105
+ - spec/data/bin/act-like.rb
106
+ - spec/data/bin/arp-scan
107
+ - spec/spec_helper.rb
108
+ - spec/whiff/arp_scan_spec.rb
109
+ - whiff.gemspec
110
+ homepage: https://github.com/chaserx/whiff
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.1.11
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: A ruby wrapper for arp-scan.
134
+ test_files:
135
+ - spec/data/arp-scan/9489ad861b94a4dd85e0b7faa03e6dd1/exit_code
136
+ - spec/data/arp-scan/9489ad861b94a4dd85e0b7faa03e6dd1/stderr
137
+ - spec/data/arp-scan/9489ad861b94a4dd85e0b7faa03e6dd1/stdout
138
+ - spec/data/bin/act-like.rb
139
+ - spec/data/bin/arp-scan
140
+ - spec/spec_helper.rb
141
+ - spec/whiff/arp_scan_spec.rb