arp_scan 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/arp_scan.rb +1 -1
- data/lib/arp_scan/arp_scanner.rb +5 -5
- data/lib/arp_scan/host.rb +14 -0
- data/lib/arp_scan/scan_report.rb +24 -1
- data/lib/arp_scan/scan_result_processor.rb +24 -0
- data/lib/arp_scan/version.rb +1 -1
- data/spec/arp_scan_spec.rb +14 -5
- data/spec/arp_scanner_spec.rb +10 -0
- data/spec/host_spec.rb +19 -0
- data/spec/scan_report_spec.rb +48 -5
- data/spec/scan_result_processor_spec.rb +44 -0
- data/spec/test_output.txt +6 -0
- metadata +11 -3
- data/lib/arp_scan/output_processor.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21449e6fd38960eb78e357a1db2e75022ec3a0cd
|
4
|
+
data.tar.gz: 2b23e39343027d0366e1caa578f68c31722f8542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 819fbd9535f90d617d3bbe3448aea31e50fe155cafb44e25fd8c03d2b6332e14b5b42a6a5e35a9fbca3a112938eb181e07c3777fd1e02097d47b9bafc74ef10f
|
7
|
+
data.tar.gz: cc4ad8109f6426074b01f1dddd5b5affb7bc9439658517594331b731b091534aacba601b7cd4164e2361d83cbb0278a19648788c437178445700b7efe3129f95
|
data/README.md
CHANGED
data/lib/arp_scan.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative "./arp_scan/version"
|
2
2
|
require_relative "./arp_scan/arp_scanner"
|
3
3
|
require_relative "./arp_scan/scan_report"
|
4
|
-
require_relative "./arp_scan/
|
4
|
+
require_relative "./arp_scan/scan_result_processor"
|
5
5
|
require_relative "./arp_scan/host"
|
6
6
|
|
7
7
|
module ARPScan
|
data/lib/arp_scan/arp_scanner.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative './
|
1
|
+
require_relative './scan_result_processor'
|
2
2
|
|
3
3
|
module ARPScan
|
4
4
|
module ARPScanner
|
@@ -18,12 +18,12 @@ module ARPScan
|
|
18
18
|
return nil
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
21
|
def self.scan(argument_string = nil)
|
23
|
-
|
24
|
-
|
25
|
-
OutputProcessor.process(output_string)
|
22
|
+
result_string = `#{which 'arp-scan'} #{argument_string}`
|
23
|
+
ScanResultProcessor.process(result_string)
|
26
24
|
end
|
25
|
+
|
26
|
+
private_class_method :which
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/lib/arp_scan/host.rb
CHANGED
data/lib/arp_scan/scan_report.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ARPScan
|
2
2
|
class ScanReport
|
3
3
|
|
4
|
-
attr_reader :interface, :datalink, :version, :range_size, :scan_time, :scan_rate, :reply_count
|
4
|
+
attr_reader :hosts, :interface, :datalink, :version, :range_size, :scan_time, :scan_rate, :reply_count
|
5
5
|
|
6
6
|
def initialize(hash)
|
7
7
|
@hosts = hash[:hosts]
|
@@ -13,5 +13,28 @@ module ARPScan
|
|
13
13
|
@scan_rate = Float(hash[:scan_rate])
|
14
14
|
@reply_count = Integer(hash[:reply_count])
|
15
15
|
end
|
16
|
+
|
17
|
+
def to_array
|
18
|
+
self.instance_variables.map do |var|
|
19
|
+
if var == :@hosts
|
20
|
+
self.instance_variable_get(var).map {|host| host.to_array}
|
21
|
+
else
|
22
|
+
self.instance_variable_get(var)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{ :hosts => @hosts.map {|host| host.to_hash},
|
29
|
+
:interface => @interface,
|
30
|
+
:datalink => @datalink,
|
31
|
+
:version => @version,
|
32
|
+
:range_size => @range_size,
|
33
|
+
:scan_time => @scan_time,
|
34
|
+
:scan_rate => @scan_rate,
|
35
|
+
:reply_count => @reply_count
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
16
39
|
end
|
17
40
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative './host'
|
2
|
+
require_relative './scan_report'
|
3
|
+
|
4
|
+
module ARPScan
|
5
|
+
module ScanResultProcessor
|
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
|
+
Scan_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
|
+
results = {}
|
13
|
+
results[:hosts] = string.scan(Host_Entry_Regex).map {|entry| Host.new(*entry)}
|
14
|
+
results[:interface],
|
15
|
+
results[:datalink] = string.scan(Interface_Summary_Regex)[0]
|
16
|
+
results[:version],
|
17
|
+
results[:range_size],
|
18
|
+
results[:scan_time],
|
19
|
+
results[:scan_rate],
|
20
|
+
results[:reply_count] = string.scan(Scan_Summary_Regex)[0]
|
21
|
+
ScanReport.new(results)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/arp_scan/version.rb
CHANGED
data/spec/arp_scan_spec.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
-
require '../lib/arp_scan
|
1
|
+
require '../lib/arp_scan'
|
2
2
|
|
3
|
-
describe ARPScan
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
RSpec.describe ARPScan do
|
4
|
+
report = ARPScan('-l')
|
5
|
+
|
6
|
+
it "is a method you can pass arp-scan arguments to as a string" do
|
7
|
+
expect(ARPScan('-l').class).to eq(ARPScan::ScanReport)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns a nested hash of attributes" do
|
11
|
+
expect(report.to_hash.class).to eq(Hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a nested array of attributes" do
|
15
|
+
expect(report.to_array.class).to eq(Array)
|
7
16
|
end
|
8
17
|
end
|
data/spec/host_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require '../lib/arp_scan'
|
2
|
+
|
3
|
+
RSpec.describe ARPScan::Host do
|
4
|
+
|
5
|
+
host = ARPScan::Host.new('10.0.0.1', '00:11:22:33:44:55', "NIC Manufacturer")
|
6
|
+
|
7
|
+
it "contains the host's IP address" do
|
8
|
+
expect(host.ip_addr).to eq('10.0.0.1')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "contains the host's MAC address" do
|
12
|
+
expect(host.mac).to eq('00:11:22:33:44:55')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "contians the host's OUI information" do
|
16
|
+
expect(host.oui).to eq('NIC Manufacturer')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/spec/scan_report_spec.rb
CHANGED
@@ -1,8 +1,51 @@
|
|
1
|
-
require '../lib/arp_scan
|
1
|
+
require '../lib/arp_scan'
|
2
2
|
|
3
|
-
describe ARPScan
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
RSpec.describe ARPScan::ScanReport do
|
4
|
+
|
5
|
+
report_hash = {
|
6
|
+
:hosts => [ARPScan::Host.new(*['10.0.0.1', '00:11:22:33:44:55', 'NIC Manufacturer'])],
|
7
|
+
:interface => "eth0",
|
8
|
+
:datalink => "EN10MB (Ethernet)",
|
9
|
+
:version => "1.8.1",
|
10
|
+
:range_size => 256,
|
11
|
+
:scan_time => 1.503,
|
12
|
+
:scan_rate => 170.33,
|
13
|
+
:reply_count => 1
|
14
|
+
}
|
15
|
+
|
16
|
+
scan_report = ARPScan::ScanReport.new(report_hash)
|
17
|
+
|
18
|
+
it "has a list of zero or more responding hosts" do
|
19
|
+
expect(scan_report.hosts.first.class).to eq(ARPScan::Host)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "reports the network interface used to scan" do
|
23
|
+
expect(scan_report.interface).to eq("eth0")
|
7
24
|
end
|
25
|
+
|
26
|
+
it "reports the datalink type of the network interface used to scan" do
|
27
|
+
expect(scan_report.datalink).to eq('EN10MB (Ethernet)')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "reports the version of `arp-scan` used for the scan" do
|
31
|
+
expect(scan_report.version).to eq('1.8.1')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "reports the size of the range of scanned IPs" do
|
35
|
+
expect(scan_report.range_size).to eq(256)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "reports the duration of the scan in seconds" do
|
39
|
+
expect(scan_report.scan_time).to eq(1.503)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "reports the scan rate in hosts per second" do
|
43
|
+
expect(scan_report.scan_rate).to eq(170.33)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "reports the number of hosts that responded" do
|
47
|
+
expect(scan_report.reply_count).to eq(1)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
8
51
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require '../lib/arp_scan'
|
2
|
+
|
3
|
+
RSpec.describe ARPScan::ScanResultProcessor do
|
4
|
+
|
5
|
+
report_string = File.read './test_output.txt'
|
6
|
+
report = ARPScan::ScanResultProcessor.process(report_string)
|
7
|
+
|
8
|
+
it "processes arp-scan output to create a ScanReport object" do
|
9
|
+
expect(report.class).to eq(ARPScan::ScanReport)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "builds an array of Host objects" do
|
13
|
+
expect(report.hosts[0].class).to eq(ARPScan::Host)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "parses the scan interface name" do
|
17
|
+
expect(report.interface).to eq("eth0")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "parses the datalink type information" do
|
21
|
+
expect(report.datalink).to eq("EN10MB (Ethernet)")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "parses the version of arp-scan that ran the scan" do
|
25
|
+
expect(report.version).to eq('1.8.1')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "parses the number of hosts scanned" do
|
29
|
+
expect(report.range_size).to eq(256)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "parses the duration of the scan in seconds" do
|
33
|
+
expect(report.scan_time).to eq(1.494)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "parses the rate of the scan in hosts per second" do
|
37
|
+
expect(report.scan_rate).to eq(171.35)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "parses the number of hosts that responded to the scan" do
|
41
|
+
expect(report.reply_count).to eq(1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Interface: eth0, datalink type: EN10MB (Ethernet)
|
2
|
+
Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
|
3
|
+
10.0.0.1 00:11:22:33:44:55 NIC Manufacturer
|
4
|
+
|
5
|
+
1 packets received by filter, 0 packets dropped by kernel
|
6
|
+
Ending arp-scan 1.8.1: 256 hosts scanned in 1.494 seconds (171.35 hosts/sec). 1 responded
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arp_scan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Rodrigues
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,11 +52,15 @@ files:
|
|
52
52
|
- lib/arp_scan.rb
|
53
53
|
- lib/arp_scan/arp_scanner.rb
|
54
54
|
- lib/arp_scan/host.rb
|
55
|
-
- lib/arp_scan/output_processor.rb
|
56
55
|
- lib/arp_scan/scan_report.rb
|
56
|
+
- lib/arp_scan/scan_result_processor.rb
|
57
57
|
- lib/arp_scan/version.rb
|
58
58
|
- spec/arp_scan_spec.rb
|
59
|
+
- spec/arp_scanner_spec.rb
|
60
|
+
- spec/host_spec.rb
|
59
61
|
- spec/scan_report_spec.rb
|
62
|
+
- spec/scan_result_processor_spec.rb
|
63
|
+
- spec/test_output.txt
|
60
64
|
homepage: ''
|
61
65
|
licenses:
|
62
66
|
- MIT
|
@@ -83,4 +87,8 @@ specification_version: 4
|
|
83
87
|
summary: A ruby wrapper for the arp-scan utility.
|
84
88
|
test_files:
|
85
89
|
- spec/arp_scan_spec.rb
|
90
|
+
- spec/arp_scanner_spec.rb
|
91
|
+
- spec/host_spec.rb
|
86
92
|
- spec/scan_report_spec.rb
|
93
|
+
- spec/scan_result_processor_spec.rb
|
94
|
+
- spec/test_output.txt
|
@@ -1,24 +0,0 @@
|
|
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).map {|entry| Host.new(*entry)}
|
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
|
-
ScanReport.new(report)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|