arp_scan 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: 34dd3d80cf5837da8b1fbaba13bdf550e7ce1cb7
4
- data.tar.gz: 1192b2fbba626243f283c26c86f86ae14c3d42dc
2
+ SHA256:
3
+ metadata.gz: 768a6997ecf0acffce32b3d52a16994e892b8f6fd93ec887613aebd478a6a86b
4
+ data.tar.gz: d8c053296aae885d75e79b70a71d4e7264fdc3f5cf61c84d65b3019b89e56262
5
5
  SHA512:
6
- metadata.gz: 12f73da6dd9d7e339ca33b02d334015d736e1be0b65355450e78feffce5154df927914e7cb4d1a491b908db697723ce484693c1e1650a7e389a7b71f52eac794
7
- data.tar.gz: 4fdfbb69b73022af9ebda830a85ea58bff8a06fc876e21e439884cf53c1d0d99cd8ea36ac671fc5fa46b3dccbe02761904a78df9d2c3bf71194712be068bb5fa
6
+ metadata.gz: 62d6e68337f32a52808e63dae880d09191b3b353c4338e4b05ee4349ed23572c594badb21af97a1336bba20dbad6b1d5aec23889acc16de63aa3e9e1ce8abbed
7
+ data.tar.gz: af52cd4506b2a847041e296fbf9d2483a0fb23a2c5e520b45168850ef986105736be7e0512832a88b39390c218a7eb5df5e10d233566af9107f9a8c1b745ebf6
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  group :test do
@@ -6,4 +8,4 @@ group :test do
6
8
  end
7
9
 
8
10
  # Specify your gem's dependencies in arp_scan.gemspec
9
- #gemspec
11
+ # gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.4.4)
5
+ rspec (3.0.0)
6
+ rspec-core (~> 3.0.0)
7
+ rspec-expectations (~> 3.0.0)
8
+ rspec-mocks (~> 3.0.0)
9
+ rspec-core (3.0.4)
10
+ rspec-support (~> 3.0.0)
11
+ rspec-expectations (3.0.4)
12
+ diff-lcs (>= 1.2.0, < 2.0)
13
+ rspec-support (~> 3.0.0)
14
+ rspec-mocks (3.0.4)
15
+ rspec-support (~> 3.0.0)
16
+ rspec-support (3.0.4)
17
+
18
+ PLATFORMS
19
+ x86_64-linux
20
+
21
+ DEPENDENCIES
22
+ rspec
23
+ rspec-support (~> 3.0.0)
24
+
25
+ BUNDLED WITH
26
+ 2.2.15
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ARPScan
2
2
 
3
- [![arp_scan API
4
- Documentation](https://www.omniref.com/ruby/gems/arp_scan.png)](https://www.omniref.com/ruby/gems/arp_scan)
3
+ [![Gem Version](https://badge.fury.io/rb/arp_scan.svg)](http://badge.fury.io/rb/arp_scan)
4
+ <a href="https://codeclimate.com/github/mikerodrigues/arp_scan"><img src="https://codeclimate.com/github/mikerodrigues/arp_scan/badges/gpa.svg" /></a>
5
5
 
6
6
  Very simple wrapper for using and parsing output from `arp-scan`.
7
7
 
data/arp_scan.gemspec CHANGED
@@ -1,23 +1,22 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'arp_scan/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "arp_scan"
8
+ spec.name = 'arp_scan'
8
9
  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 = "https://github.com/mikerodrigues/arp_scan"
14
- spec.license = "MIT"
10
+ spec.authors = ['Michael Rodrigues']
11
+ spec.email = ['mikebrodrigues@gmail.com']
12
+ spec.summary = 'A ruby wrapper for the arp-scan utility.'
13
+ spec.description = 'Use the arp-scan utility from your ruby programs.'
14
+ spec.homepage = 'https://github.com/mikerodrigues/arp_scan'
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
22
  end
data/lib/arp_scan.rb CHANGED
@@ -1,8 +1,10 @@
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/scan_result_processor"
5
- require_relative "./arp_scan/host"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './arp_scan/version'
4
+ require_relative './arp_scan/arp_scanner'
5
+ require_relative './arp_scan/scan_report'
6
+ require_relative './arp_scan/scan_result_processor'
7
+ require_relative './arp_scan/host'
6
8
 
7
9
  # This module just acts as a namespace for the gem.
8
10
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './scan_result_processor'
2
4
 
3
5
  module ARPScan
@@ -13,10 +15,10 @@ module ARPScan
13
15
  def self.which(cmd)
14
16
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
15
17
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
16
- exts.each { |ext|
18
+ exts.each do |ext|
17
19
  exe = File.join(path, "#{cmd}#{ext}")
18
20
  return exe if File.executable?(exe) && !File.directory?(exe)
19
- }
21
+ end
20
22
  end
21
23
  raise 'arp-scan binary not found, make sure it is installed'
22
24
  end
@@ -33,4 +35,3 @@ module ARPScan
33
35
  private_class_method :which
34
36
  end
35
37
  end
36
-
data/lib/arp_scan/host.rb CHANGED
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ARPScan
2
4
  # Abstracts replying hosts from the arp-scan output.
3
5
  #
4
6
  class Host
5
-
6
7
  # The IP address of the host.
7
8
  #
8
9
  attr_reader :ip_addr
@@ -27,19 +28,17 @@ module ARPScan
27
28
  # Returns a hash representation of the Host object.
28
29
  #
29
30
  def to_hash
30
- { :ip_addr => @ip_addr,
31
- :mac => @mac,
32
- :oui => @oui
33
- }
31
+ { ip_addr: @ip_addr,
32
+ mac: @mac,
33
+ oui: @oui }
34
34
  end
35
35
 
36
36
  # Returns an array representation of the Host object.
37
37
  #
38
38
  def to_array
39
- [ @ip_addr,
40
- @mac,
41
- @oui
42
- ]
39
+ [@ip_addr,
40
+ @mac,
41
+ @oui]
43
42
  end
44
43
  end
45
44
  end
@@ -1,10 +1,10 @@
1
- module ARPScan
1
+ # frozen_string_literal: true
2
2
 
3
+ module ARPScan
3
4
  # This class abstracts the string output from arp-scan into an Object. A
4
5
  # ScanReports are usually created through the ScanResultProcessor module.
5
6
  #
6
7
  class ScanReport
7
-
8
8
  # Array of Host objects.
9
9
  #
10
10
  attr_reader :hosts
@@ -58,11 +58,11 @@ module ARPScan
58
58
  # scan, and an array of Host arrays comprise the array.
59
59
  #
60
60
  def to_array
61
- self.instance_variables.map do |var|
61
+ instance_variables.map do |var|
62
62
  if var == :@hosts
63
- self.instance_variable_get(var).map {|host| host.to_array}
63
+ instance_variable_get(var).map(&:to_array)
64
64
  else
65
- self.instance_variable_get(var)
65
+ instance_variable_get(var)
66
66
  end
67
67
  end
68
68
  end
@@ -71,17 +71,15 @@ module ARPScan
71
71
  # and array of Host hashes comprise the hash.
72
72
  #
73
73
  def to_hash
74
- { :hosts => @hosts.map {|host| host.to_hash},
75
- :interface => @interface,
76
- :datalink => @datalink,
77
- :version => @version,
78
- :range_size => @range_size,
79
- :scan_time => @scan_time,
80
- :scan_rate => @scan_rate,
81
- :reply_count => @reply_count,
82
- :arguments => @arguments
83
- }
74
+ { hosts: @hosts.map(&:to_hash),
75
+ interface: @interface,
76
+ datalink: @datalink,
77
+ version: @version,
78
+ range_size: @range_size,
79
+ scan_time: @scan_time,
80
+ scan_rate: @scan_rate,
81
+ reply_count: @reply_count,
82
+ arguments: @arguments }
84
83
  end
85
-
86
84
  end
87
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './host'
2
4
  require_relative './scan_report'
3
5
 
@@ -6,19 +8,18 @@ module ARPScan
6
8
  # output.
7
9
  #
8
10
  module ScanResultProcessor
9
-
10
11
  # Regex to capture IP address, MAC address, and OUI information
11
12
  #
12
- Host_Entry_Regex = /(\d+.\d+.\d+.\d+)\s(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)\s(.*)/
13
-
13
+ HOST_ENTRY_REGEX = /(\d+.\d+.\d+.\d+)\s(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)\s(.*)/.freeze
14
+
14
15
  # Regex to capture interface and datalink
15
16
  #
16
- Interface_Summary_Regex = /Interface: (?<interface>.+), datalink type: (?<datalink>.*$)/
17
+ INTERFACE_SUMMARY_REGEX = /Interface: (?<interface>.+), datalink type: (?<datalink>.*$)/.freeze
17
18
 
18
19
  # Regex to capture arp-scan version, scan range size, scan time, scan rate,
19
20
  # and the number of responding hosts.
20
21
  #
21
- Scan_Summary_Regex = /Ending arp-scan (?<version>.*): (?<range_size>.*) hosts scanned in (?<scan_time>.*) seconds \((?<scan_rate>.*) hosts\/sec\). (?<reply_count>.*) responded/
22
+ SCAN_SUMMARY_REGEX = %r{Ending arp-scan (?<version>.*): (?<range_size>.*) hosts scanned in (?<scan_time>.*) seconds \((?<scan_rate>.*) hosts/sec\). (?<reply_count>.*) responded}.freeze
22
23
 
23
24
  # This method does the actual processing of the arp-scan result string. It
24
25
  # uses the Regexes to capture data then passes the results to ScanRepor.new
@@ -26,14 +27,14 @@ module ARPScan
26
27
  #
27
28
  def self.process(string, arguments)
28
29
  results = {}
29
- results[:hosts] = string.scan(Host_Entry_Regex).map {|entry| Host.new(*entry)}
30
+ results[:hosts] = string.scan(HOST_ENTRY_REGEX).map { |entry| Host.new(*entry) }
30
31
  results[:interface],
31
- results[:datalink] = string.scan(Interface_Summary_Regex)[0]
32
+ results[:datalink] = string.scan(INTERFACE_SUMMARY_REGEX)[0]
32
33
  results[:version],
33
34
  results[:range_size],
34
35
  results[:scan_time],
35
36
  results[:scan_rate],
36
- results[:reply_count] = string.scan(Scan_Summary_Regex)[0]
37
+ results[:reply_count] = string.scan(SCAN_SUMMARY_REGEX)[0]
37
38
  results[:arguments] = arguments
38
39
  ScanReport.new(results)
39
40
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ARPScan
2
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
3
5
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './spec_helper.rb'
2
4
 
3
5
  RSpec.describe ARPScan do
4
- report = ARPScan('-l')
5
- it "is a method" do
6
+ ARPScan('-l')
7
+ it 'is a method' do
6
8
  expect(ARPScan.respond_to?('__send__')).to eq(true)
7
9
  end
8
10
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './spec_helper'
2
4
 
3
5
  module ARPScan
4
6
  describe ARPScanner do
5
- describe "#scan" do
6
- it "accepts arp-scan arguments as a string" do
7
+ describe '#scan' do
8
+ it 'accepts arp-scan arguments as a string' do
7
9
  expect(ARPScanner.scan('-l').class).to eq(ScanReport)
8
10
  end
9
11
  end
data/spec/host_spec.rb CHANGED
@@ -1,27 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './spec_helper'
2
4
 
3
5
  module ARPScan
4
6
  describe Host do
7
+ host = Host.new('10.0.0.1', '00:11:22:33:44:55', 'NIC Manufacturer')
5
8
 
6
- host = Host.new('10.0.0.1', '00:11:22:33:44:55', "NIC Manufacturer")
7
-
8
- describe "#ip_addr" do
9
+ describe '#ip_addr' do
9
10
  it "returns the host's IP address" do
10
11
  expect(host.ip_addr).to eq('10.0.0.1')
11
12
  end
12
13
  end
13
14
 
14
- describe "#mac" do
15
+ describe '#mac' do
15
16
  it "returns the host's MAC address" do
16
17
  expect(host.mac).to eq('00:11:22:33:44:55')
17
18
  end
18
19
  end
19
20
 
20
- describe "#oui" do
21
+ describe '#oui' do
21
22
  it "returns the host's OUI information" do
22
23
  expect(host.oui).to eq('NIC Manufacturer')
23
24
  end
24
25
  end
25
-
26
26
  end
27
27
  end
@@ -1,73 +1,74 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './spec_helper'
2
4
 
3
5
  module ARPScan
4
6
  describe ScanReport do
5
-
6
7
  report_hash = {
7
- :hosts => [Host.new(*['10.0.0.1', '00:11:22:33:44:55', 'NIC Manufacturer'])],
8
- :interface => "eth0",
9
- :datalink => "EN10MB (Ethernet)",
10
- :version => "1.8.1",
11
- :range_size => 256,
12
- :scan_time => 1.503,
13
- :scan_rate => 170.33,
14
- :reply_count => 1,
15
- :arguments => '-l'
8
+ hosts: [Host.new('10.0.0.1', '00:11:22:33:44:55', 'NIC Manufacturer')],
9
+ interface: 'eth0',
10
+ datalink: 'EN10MB (Ethernet)',
11
+ version: '1.8.1',
12
+ range_size: 256,
13
+ scan_time: 1.503,
14
+ scan_rate: 170.33,
15
+ reply_count: 1,
16
+ arguments: '-l'
16
17
  }
17
18
 
18
19
  scan_report = ScanReport.new(report_hash)
19
20
 
20
- describe "#hosts" do
21
- it "returns an Array of Host objects" do
21
+ describe '#hosts' do
22
+ it 'returns an Array of Host objects' do
22
23
  expect(scan_report.hosts.class).to eq(Array)
23
24
  expect(scan_report.hosts.first.class).to eq(Host)
24
25
  end
25
26
  end
26
27
 
27
- describe "#interface" do
28
- it "returns the network interface used to scan" do
29
- expect(scan_report.interface).to eq("eth0")
28
+ describe '#interface' do
29
+ it 'returns the network interface used to scan' do
30
+ expect(scan_report.interface).to eq('eth0')
30
31
  end
31
32
  end
32
33
 
33
- describe "#datalink" do
34
- it "returns the datalink type of the network interface used to scan" do
34
+ describe '#datalink' do
35
+ it 'returns the datalink type of the network interface used to scan' do
35
36
  expect(scan_report.datalink).to eq('EN10MB (Ethernet)')
36
37
  end
37
38
  end
38
39
 
39
- describe "#version" do
40
- it "returns the version of `arp-scan` used for the scan" do
40
+ describe '#version' do
41
+ it 'returns the version of `arp-scan` used for the scan' do
41
42
  expect(scan_report.version).to eq('1.8.1')
42
43
  end
43
44
  end
44
45
 
45
- describe "#range_size" do
46
- it "returns the size of the range of scanned IPs" do
46
+ describe '#range_size' do
47
+ it 'returns the size of the range of scanned IPs' do
47
48
  expect(scan_report.range_size).to eq(256)
48
49
  end
49
50
  end
50
51
 
51
- describe "#scan_time" do
52
- it "returns the duration of the scan in seconds" do
52
+ describe '#scan_time' do
53
+ it 'returns the duration of the scan in seconds' do
53
54
  expect(scan_report.scan_time).to eq(1.503)
54
55
  end
55
56
  end
56
57
 
57
- describe "#scan_rate" do
58
- it "returns the scan rate in hosts per second" do
58
+ describe '#scan_rate' do
59
+ it 'returns the scan rate in hosts per second' do
59
60
  expect(scan_report.scan_rate).to eq(170.33)
60
61
  end
61
62
  end
62
63
 
63
- describe "#reply_count" do
64
- it "returns the number of hosts that responded" do
64
+ describe '#reply_count' do
65
+ it 'returns the number of hosts that responded' do
65
66
  expect(scan_report.reply_count).to eq(1)
66
67
  end
67
68
  end
68
69
 
69
- describe "#arguments" do
70
- it "returns the argument string used to scan" do
70
+ describe '#arguments' do
71
+ it 'returns the argument string used to scan' do
71
72
  expect(scan_report.arguments).to eq('-l')
72
73
  end
73
74
  end
@@ -1,50 +1,51 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './spec_helper'
2
4
 
3
5
  module ARPScan
4
6
  describe ScanResultProcessor do
5
-
6
7
  argument_string = '-l'
7
8
  report_string = File.read './test_output.txt'
8
9
  report = ARPScan::ScanResultProcessor.process(report_string, argument_string)
9
10
 
10
- describe "#process" do
11
- it "processes arp-scan output to create a ScanReport object" do
11
+ describe '#process' do
12
+ it 'processes arp-scan output to create a ScanReport object' do
12
13
  expect(report.class).to eq(ARPScan::ScanReport)
13
14
  end
14
15
 
15
- it "builds an array of Host objects" do
16
+ it 'builds an array of Host objects' do
16
17
  expect(report.hosts[0].class).to eq(ARPScan::Host)
17
18
  end
18
19
 
19
- it "parses the scan interface name" do
20
- expect(report.interface).to eq("eth0")
20
+ it 'parses the scan interface name' do
21
+ expect(report.interface).to eq('eth0')
21
22
  end
22
23
 
23
- it "parses the datalink type information" do
24
- expect(report.datalink).to eq("EN10MB (Ethernet)")
24
+ it 'parses the datalink type information' do
25
+ expect(report.datalink).to eq('EN10MB (Ethernet)')
25
26
  end
26
27
 
27
- it "parses the version of arp-scan that ran the scan" do
28
+ it 'parses the version of arp-scan that ran the scan' do
28
29
  expect(report.version).to eq('1.8.1')
29
30
  end
30
31
 
31
- it "parses the number of hosts scanned" do
32
+ it 'parses the number of hosts scanned' do
32
33
  expect(report.range_size).to eq(256)
33
34
  end
34
35
 
35
- it "parses the duration of the scan in seconds" do
36
+ it 'parses the duration of the scan in seconds' do
36
37
  expect(report.scan_time).to eq(1.494)
37
38
  end
38
39
 
39
- it "parses the rate of the scan in hosts per second" do
40
+ it 'parses the rate of the scan in hosts per second' do
40
41
  expect(report.scan_rate).to eq(171.35)
41
42
  end
42
43
 
43
- it "parses the number of hosts that responded to the scan" do
44
+ it 'parses the number of hosts that responded to the scan' do
44
45
  expect(report.reply_count).to eq(1)
45
46
  end
46
47
 
47
- it "includes the argument string in the report" do
48
+ it 'includes the argument string in the report' do
48
49
  expect(report.arguments).to eq('-l')
49
50
  end
50
51
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require '../lib/arp_scan'
metadata CHANGED
@@ -1,44 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arp_scan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Rodrigues
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-22 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.
11
+ date: 2021-07-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Use the arp-scan utility from your ruby programs.
42
14
  email:
43
15
  - mikebrodrigues@gmail.com
44
16
  executables: []
@@ -46,6 +18,7 @@ extensions: []
46
18
  extra_rdoc_files: []
47
19
  files:
48
20
  - Gemfile
21
+ - Gemfile.lock
49
22
  - LICENSE.txt
50
23
  - README.md
51
24
  - arp_scan.gemspec
@@ -81,8 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
54
  - !ruby/object:Gem::Version
82
55
  version: '0'
83
56
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.4.5
57
+ rubygems_version: 3.2.3
86
58
  signing_key:
87
59
  specification_version: 4
88
60
  summary: A ruby wrapper for the arp-scan utility.