Class: ArpScanner
- Inherits:
-
Object
- Object
- ArpScanner
- Defined in:
- lib/arpscanner.rb
Instance Method Summary collapse
-
#initialize(nic: `ip addr`[/(?<=global )\w+/], vendors: {}) ⇒ ArpScanner
constructor
options: nic: e.g.
- #scan ⇒ Object
Constructor Details
#initialize(nic: `ip addr`[/(?<=global )\w+/], vendors: {}) ⇒ ArpScanner
options: nic: e.g. eth0, enp2s0f0
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/arpscanner.rb', line 13 def initialize(nic: `ip addr`[/(?<=global )\w+/], vendors: {}) package = 'arp-scan' @vendors = vendors found = `dpkg --get-selections | grep #{package}` if found.empty? then raise 'ArpScanner: arp-scan package not found'.error end @arpscan_cmd = "sudo #{package} --interface=#{nic} --localnet" end |
Instance Method Details
#scan ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/arpscanner.rb', line 28 def scan() a = `#{@arpscan_cmd}`.lines a2 = a[2..-3].map {|x| %i(ip mac mfr).zip(x.chomp.split("\t")).to_h} # Add additional vendors h = {/^b8:27:eb:/ => 'Raspberry Pi Foundation'}.merge(@vendors) a2.map! do |x| _, vendor = h.detect {|mac, mfr| x[:mac] =~ mac } x[:mfr] = vendor if vendor x end @dx = Dynarex.new @dx.import a2 end |