Class: BetterCap::Network::ArpReader

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/network/arp_reader.rb

Overview

This class is responsible for reading the computer ARP table.

Class Method Summary collapse

Class Method Details

.find_address(address) ⇒ Object

Parse the ARP cache searching for the given IP address and return its MAC if found, otherwise nil.


39
40
41
42
43
44
45
46
# File 'lib/bettercap/network/arp_reader.rb', line 39

def self.find_address( address )
  self.parse_cache do |ip,mac|
    if ip == address
      return mac
    end
  end
  nil
end

.find_mac(address) ⇒ Object

Parse the ARP cache searching for the given MAC address and return its IP if found, otherwise nil.


50
51
52
53
54
55
56
57
# File 'lib/bettercap/network/arp_reader.rb', line 50

def self.find_mac( address )
  self.parse_cache do |ip,mac|
    if mac == address
      return ip
    end
  end
  nil
end

.parse(ctx) ⇒ Object

Parse the current ARP cache and return a list of BetterCap::Target objects which are found inside it, using the ctx BetterCap::Context instance.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bettercap/network/arp_reader.rb', line 17

def self.parse( ctx )
  targets = []
  self.parse_cache do |ip,mac|
    if ip != ctx.gateway and ip != ctx.ifconfig[:ip_saddr]
      if ctx.options.ignore_ip?(ip)
        Logger.debug "Ignoring #{ip} ..."
      else
        # reuse Target object if it's already a known address
        known = ctx.find_target ip, mac
        if known.nil?
          targets << Target.new( ip, mac )
        else
          targets << known
        end
      end
    end
  end
  targets
end