arp_scan 0.0.1

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: ad523800941924d8ef1121a6d5757b55be171ca5
4
+ data.tar.gz: 47c2452c4d7a149cdb31d4103cae7e23344ce0c7
5
+ SHA512:
6
+ metadata.gz: 2a840f2abb674944204976a51db4221b317efb1508860b060b795688d311e37a1120c564f5863d4b272de3ba7c91239205c63cb5b18a55fe25d73bfc2e7033a1
7
+ data.tar.gz: 5d1f0c22e868592708ba5f1425d1ec9b84975c9c2c3735525375e7c91a6d88e5718ff0977a230baca2064458e2a10a75e3e8c6e5b3c23be02e9f4b6ec5c8d450
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in arp_scan.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michael Rodrigues
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,86 @@
1
+ # ARPScan
2
+
3
+ Very simple wrapper for using and parsing output from `arp-scan`.
4
+
5
+ You will need to make sure `arp-scan` is installed. See the arp-scan homepage at http://www.nta-monitor.com/tools/arp-scan/
6
+
7
+ You'll also need superuser privileges to run `arp-scan`, you have have a few
8
+ options but be sure to understand what you're doing before you do it:
9
+
10
+ * Edit `/etc/sudoers` to allow user to run `arp-scan` as root without a
11
+ password.
12
+
13
+ `user host = (root) NOPASSWD: /usr/bin/arp-scan`
14
+
15
+ * Set the SUID bit on the `arp-scan` bin:
16
+
17
+ sudo chmod u+s /usr/bin/arp-scan`
18
+
19
+ * Run your Ruby code as root (I wouldn't do this)
20
+
21
+ I use the SUID method but if you have other people logging into your machine you
22
+ should probably go with the `/etc/sudoers` method.
23
+
24
+
25
+ ## Notes
26
+
27
+ This code is untested and will hopefully be refactored soon.
28
+
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem 'arp_scan', :git => 'git://github.com/mikerodrigues/arp_scan.git'
36
+ ```
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install arp_scan
45
+
46
+ ## Usage
47
+
48
+ No argument parsing is done by the gem, it takes the same arguments as
49
+ `arp-scan` and just passes them to the binary. The result is returned as a
50
+ ScanReport object which makes it easy to iterate through hosts as well as see
51
+ metainfo about the scan itself.
52
+
53
+ Scanning is easy:
54
+
55
+ require 'arp_scan'
56
+
57
+ report = ARPScan('--localnet')
58
+
59
+ report.datalink => "EN10MB (Ethernet)",
60
+ report.interface => "eth0"
61
+ report.range_size => "256"
62
+ report.reply_count => "2"
63
+ report.scan_rate => "169.99" # hosts/sec
64
+ report.scan_time => "1.586" # seconds
65
+ report.version => "1.8.1" # arp-scan version
66
+
67
+ Each `ScanReport` also holds zero or more `Host` objects representing founds
68
+ hosts:
69
+
70
+ first_host = report.hosts.first
71
+ first_host.ip_addr => '10.0.0.1'
72
+ first_host.mac => '00:11:22:33:44:55'
73
+ first_host.oui => "NIC Manufacturer"
74
+
75
+
76
+
77
+
78
+
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it ( https://github.com/mikerodrigues/arp_scan/fork )
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create a new Pull Request
data/arp_scan.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'arp_scan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "arp_scan"
8
+ spec.version = ARPScan::VERSION
9
+ spec.authors = ["Michael Rodrigues"]
10
+ spec.email = ["mikebrodrigues@gmail.com"]
11
+ spec.summary = %q{A ruby wrapper for the arp-scan utility.}
12
+ spec.description = %q{Easily use the arp_scan utility from within your ruby programs.}
13
+ spec.homepage = ""
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,29 @@
1
+ require_relative './arp_scanner'
2
+
3
+ module ARPScan
4
+ module ARPScanner
5
+
6
+ # I got this method from: http://stackoverflow.com/questions/2108727
7
+ # Cross-platform way of finding an executable in the $PATH.
8
+ #
9
+ # which('ruby') #=> /usr/bin/ruby
10
+ def self.which(cmd)
11
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
12
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
13
+ exts.each { |ext|
14
+ exe = File.join(path, "#{cmd}#{ext}")
15
+ return exe if File.executable?(exe) && !File.directory?(exe)
16
+ }
17
+ end
18
+ return nil
19
+ end
20
+
21
+
22
+ def self.scan(argument_string = nil)
23
+ @arp_scan_path = which 'arp-scan'
24
+ output_string = `#{@arp_scan_path} #{argument_string}`
25
+ OutputProcessor.process(output_string)
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,11 @@
1
+ module ARPScan
2
+ class Host
3
+ attr_reader :ip_addr, :mac, :oui
4
+
5
+ def initialize(ip_addr, mac, oui)
6
+ @ip_addr = ip_addr
7
+ @mac = mac
8
+ @oui = oui
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './host'
2
+ require_relative './scan_report'
3
+
4
+ module ARPScan
5
+ module OutputProcessor
6
+
7
+ Host_Entry_Regex = /(\d+.\d+.\d+.\d+)\s(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)\s(.*)/
8
+ Interface_Summary_Regex = /Interface: (?<interface>.+), datalink type: (?<datalink>.*$)/
9
+ Received_Summary_Regex = /Ending arp-scan (?<version>.*): (?<range_size>.*) hosts scanned in (?<scan_time>.*) seconds \((?<scan_rate>.*) hosts\/sec\). (?<reply_count>.*) responded/
10
+
11
+ def self.process(string)
12
+ report = {}
13
+ report[:hosts] = string.scan(Host_Entry_Regex)
14
+ report[:interface],
15
+ report[:datalink] = string.scan(Interface_Summary_Regex)[0]
16
+ report[:version],
17
+ report[:range_size],
18
+ report[:scan_time],
19
+ report[:scan_rate],
20
+ report[:reply_count] = string.scan(Received_Summary_Regex)[0]
21
+ hosts = report[:hosts].map {|entry| Host.new(*entry)}
22
+ ScanReport.new(report)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module ARPScan
2
+ class ScanReport
3
+
4
+ attr_reader :interface, :datalink, :version, :range_size, :scan_time, :scan_rate, :reply_count
5
+
6
+ def initialize(hash)
7
+ @hosts = hash[:hosts]
8
+ @interface = hash[:interface]
9
+ @datalink = hash[:datalink]
10
+ @version = hash[:version]
11
+ @range_size = Integer(hash[:range_size])
12
+ @scan_time = Float(hash[:scan_time])
13
+ @scan_rate = Float(hash[:scan_rate])
14
+ @reply_count = Integer(hash[:reply_count])
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module ARPScan
2
+ VERSION = "0.0.1"
3
+ end
data/lib/arp_scan.rb ADDED
@@ -0,0 +1,13 @@
1
+ require_relative "./arp_scan/version"
2
+ require_relative "./arp_scan/arp_scanner"
3
+ require_relative "./arp_scan/scan_report"
4
+ require_relative "./arp_scan/output_processor"
5
+ require_relative "./arp_scan/host"
6
+
7
+ module ARPScan
8
+
9
+ end
10
+
11
+ def ARPScan(argument_string = nil)
12
+ ARPScan::ARPScanner.scan argument_string
13
+ end
@@ -0,0 +1,8 @@
1
+ require '../lib/arp_scan.rb'
2
+
3
+ describe ARPScan, '#scan' do
4
+ it 'returns a ScanReport' do
5
+ report = ARPScan.scan('-I eth0.748 128.111.186.1-128.111.186.75')
6
+ report.class.should eq(ARPScan::ScanReport)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require '../lib/arp_scan.rb'
2
+
3
+ describe ARPScan, '#scan' do
4
+ it 'returns a ScanReport' do
5
+ report = ARPScan.scan('-I eth0.748 128.111.186.1-128.111.186.75')
6
+ report.class.should eq(ARPScan::ScanReport)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arp_scan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Rodrigues
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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.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.0'
41
+ description: Easily use the arp_scan utility from within your ruby programs.
42
+ email:
43
+ - mikebrodrigues@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - LICENSE.txt
50
+ - README.md
51
+ - arp_scan.gemspec
52
+ - lib/arp_scan.rb
53
+ - lib/arp_scan/arp_scanner.rb
54
+ - lib/arp_scan/host.rb
55
+ - lib/arp_scan/output_processor.rb
56
+ - lib/arp_scan/scan_report.rb
57
+ - lib/arp_scan/version.rb
58
+ - spec/arp_scan_spec.rb
59
+ - spec/scan_report_spec.rb
60
+ homepage: ''
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.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A ruby wrapper for the arp-scan utility.
84
+ test_files:
85
+ - spec/arp_scan_spec.rb
86
+ - spec/scan_report_spec.rb