Module: ARPScan::ScanResultProcessor

Defined in:
lib/arp_scan/scan_result_processor.rb

Overview

This module is an interface for creating ScanReport objects from arp-scan output.

Constant Summary collapse

HOST_ENTRY_REGEX =

Regex to capture IP address, MAC address, and OUI information

/(\d+.\d+.\d+.\d+)\s(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)\s(.*)/
INTERFACE_SUMMARY_REGEX =

Regex to capture interface and datalink

/
^Interface:\s+(?<interface>[^,\n]+),
(?:\s*datalink)?\s*type:\s*(?<datalink>[^\n,]+?)(?=,\s*MAC:|$)
(?:,\s*MAC:\s*(?<mac>[0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){5}))?
  (?:,\s*IPv4:\s*(?<ipv4>(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)))?
  $
/x
SCAN_SUMMARY_REGEX =

Regex to capture arp-scan version, scan range size, scan time, scan rate, and the number of responding hosts.

%r{Ending arp-scan (?<version>.*): (?<range_size>.*) hosts scanned in (?<scan_time>.*) seconds \((?<scan_rate>.*) hosts/sec\). (?<reply_count>.*) responded}

Class Method Summary collapse

Class Method Details

.process(string, arguments) ⇒ Object

This method does the actual processing of the arp-scan result string. It uses the Regexes to capture data then passes the results to ScanRepor.new to return a ScanReport object.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/arp_scan/scan_result_processor.rb', line 36

def self.process(string, arguments)
  results = {}
  results[:hosts] = string.scan(HOST_ENTRY_REGEX).map { |entry| Host.new(*entry) }
  results[:interface],
    results[:datalink],
    results[:mac],
    results[:ipv4] = string.scan(INTERFACE_SUMMARY_REGEX)[0]
  results[:version],
    results[:range_size],
    results[:scan_time],
    results[:scan_rate],
    results[:reply_count] = string.scan(SCAN_SUMMARY_REGEX)[0]
  results[:arguments] = arguments
  ScanReport.new(results)
end