From 741ce924b89e518167f28060180108e08f95ef63 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Tue, 16 Feb 2016 20:15:24 +0100 Subject: [PATCH] Fixed a bug in discovery agents. --- lib/bettercap/discovery/agents/base.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/bettercap/discovery/agents/base.rb b/lib/bettercap/discovery/agents/base.rb index 38221cdc..6a810d11 100644 --- a/lib/bettercap/discovery/agents/base.rb +++ b/lib/bettercap/discovery/agents/base.rb @@ -35,7 +35,10 @@ def initialize( ctx, address = nil ) ip = ip.succ end else - unless skip_address?(@address) + if skip_address?(@address) + Logger.debug "Skipping #{@address} ..." + else + Logger.debug "Probing #{@address} ..." @ctx.packets.push( get_probe(@address) ) end end @@ -46,11 +49,20 @@ def initialize( ctx, address = nil ) # Return true if +ip+ must be skipped during discovery, otherwise false. def skip_address?(ip) # don't send probes to the gateway - ( ip == @ctx.gateway or \ - # don't send probes to our device - ip == @local_ip or \ - # don't stress endpoints we already discovered - !@ctx.find_target( ip.to_s, nil ).nil? ) + if ip == @ctx.gateway + return true + # don't send probes to our device + elsif ip == @local_ip + return true + # don't stress endpoints we already discovered + else + target = @ctx.find_target( ip.to_s, nil ) + # known target? + return false if target.nil? + # do we still need to get the mac for this target? + return ( target.mac.nil?? false : true ) + end + end # Each Discovery::Agent::Base derived class should implement this method.