From 9148ab4bb2a54c07cc7fbb136e2e8992bf6b9323 Mon Sep 17 00:00:00 2001 From: William Vu Date: Thu, 24 May 2018 16:05:24 -0500 Subject: [PATCH] Refactor OptAddressLocal logic @bcoles +1 --- lib/msf/core/opt_address_local.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/msf/core/opt_address_local.rb b/lib/msf/core/opt_address_local.rb index 7e3f0d54c6..1a39f5669b 100644 --- a/lib/msf/core/opt_address_local.rb +++ b/lib/msf/core/opt_address_local.rb @@ -15,21 +15,19 @@ class OptAddressLocal < OptAddress def normalize(value) return unless value.kind_of?(String) + return value unless interfaces.include?(value) - if interfaces.include?(value) - ip_address = NetworkInterface.addresses(value).values.flatten.map{|x| x['addr']}.select do |addr| - begin - IPAddr.new(addr).ipv4? - rescue IPAddr::InvalidAddressError - nil - end + ip_address = NetworkInterface.addresses(value).values.flatten.map{|x| x['addr']}.select do |addr| + begin + IPAddr.new(addr).ipv4? + rescue IPAddr::InvalidAddressError + nil end - - return if ip_address.blank? - return ip_address.first end - value + return if ip_address.blank? + + ip_address.first end def valid?(value, check_empty: true)