Refactor OptAddressLocal logic

@bcoles +1
GSoC/Meterpreter_Web_Console
William Vu 2018-05-24 16:05:24 -05:00
parent 6f1e75e097
commit 9148ab4bb2
1 changed files with 9 additions and 11 deletions

View File

@ -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)