cash host resolution

if we successfuly resolve the host during
the validation, then alter host to the resolved
address to avoid the overhead of subsequent
DNS requests.
This commit is contained in:
David Maloney 2014-04-22 15:34:16 -05:00
parent 0439569ffb
commit d25f0d8f6c
No known key found for this signature in database
GPG Key ID: DEDBA9DC3A913DB2
1 changed files with 2 additions and 1 deletions

View File

@ -196,12 +196,13 @@ module Metasploit
errors.add(:host, "must be a string") errors.add(:host, "must be a string")
end end
begin begin
::Rex::Socket.getaddress(host, true) resolved_host = ::Rex::Socket.getaddress(host, true)
if host =~ /^\d{1,3}(\.\d{1,3}){1,3}$/ if host =~ /^\d{1,3}(\.\d{1,3}){1,3}$/
unless host =~ Rex::Socket::MATCH_IPV4 unless host =~ Rex::Socket::MATCH_IPV4
errors.add(:host, "could not be resolved") errors.add(:host, "could not be resolved")
end end
end end
host = resolved_host
rescue rescue
errors.add(:host, "could not be resolved") errors.add(:host, "could not be resolved")
end end