Class: BetterCap::Network::ArpReader
- Inherits:
-
Object
- Object
- BetterCap::Network::ArpReader
- Defined in:
- lib/bettercap/network/arp_reader.rb
Overview
This class is responsible for reading the computer ARP table.
Class Method Summary collapse
-
.find_address(address) ⇒ Object
Parse the ARP cache searching for the given IP
address
and return its MAC if found, otherwise nil. -
.find_mac(address) ⇒ Object
Parse the ARP cache searching for the given MAC
address
and return its IP if found, otherwise nil. -
.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.
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.
43 44 45 46 47 48 49 50 |
# File 'lib/bettercap/network/arp_reader.rb', line 43 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.
54 55 56 57 58 59 60 61 |
# File 'lib/bettercap/network/arp_reader.rb', line 54 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.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bettercap/network/arp_reader.rb', line 21 def self.parse( ctx ) targets = [] self.parse_cache do |ip,mac| if ip != ctx.gateway.ip and ip != ctx.iface.ip if ctx..core.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 |